MessageHandler.c 922 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, 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(3001, 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. //offline MeterValue Interval
  3512. TempMeterValueInterval = 0;
  3513. return result;
  3514. }
  3515. int ProcessShareMemory()
  3516. {
  3517. int result = PASS;
  3518. if(InitShareMemory() == FAIL)
  3519. {
  3520. DEBUG_ERROR("InitShareMemory NG\n");
  3521. if(ShmStatusCodeData!=NULL)
  3522. {
  3523. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3524. }
  3525. result = FAIL;
  3526. }
  3527. // Model name parsing
  3528. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3529. {
  3530. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3531. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3532. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3533. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3535. ) // 'D' means DC
  3536. {
  3537. // DO series
  3538. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3539. {
  3540. SystemInitial += 1;
  3541. gunTotalNumber += 1;
  3542. gunType[gun_index] = GUN_TYPE_DO;
  3543. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3544. {
  3545. case Gun_Type_Chademo:
  3546. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3547. break;
  3548. case Gun_Type_CCS_2:
  3549. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3550. break;
  3551. case Gun_Type_GB:
  3552. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3553. break;
  3554. case Gun_Type_AC:
  3555. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3556. break;
  3557. default:
  3558. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3559. break;
  3560. }
  3561. }
  3562. }
  3563. else
  3564. {
  3565. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3566. {
  3567. SystemInitial += 1;
  3568. gunTotalNumber += 1;
  3569. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3570. {
  3571. case Gun_Type_Chademo:
  3572. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3573. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3574. break;
  3575. case Gun_Type_CCS_2:
  3576. gunType[gun_index] = GUN_TYPE_CCS;
  3577. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3578. break;
  3579. case Gun_Type_GB:
  3580. gunType[gun_index] = GUN_TYPE_GBT;
  3581. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3582. break;
  3583. case Gun_Type_AC:
  3584. gunType[gun_index] = GUN_TYPE_AC;
  3585. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3586. break;
  3587. default:
  3588. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3589. break;
  3590. }
  3591. }
  3592. }
  3593. }
  3594. else
  3595. {
  3596. DEBUG_ERROR("Model name parsing fail.\n");
  3597. result = FAIL;
  3598. }
  3599. if(result != PASS)sleep(5);
  3600. return result;
  3601. }
  3602. void checkRemoteStart(uint8_t connectorIdInt)
  3603. {
  3604. uint8_t tempIndex;
  3605. int result = PASS;
  3606. char cmdBuf[512];
  3607. //check Transaction active
  3608. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3609. {
  3610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3611. {
  3612. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3613. }
  3614. else
  3615. {
  3616. tempIndex = connectorIdInt -1;
  3617. }
  3618. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3619. {
  3620. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3621. {
  3622. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3623. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3624. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3625. {
  3626. //Reserved
  3627. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3628. }
  3629. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3631. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3632. {
  3633. //Reserved
  3634. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3635. result = FAIL;
  3636. goto end;
  3637. }
  3638. else
  3639. {
  3640. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3641. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3642. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3643. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3644. {
  3645. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3646. result = FAIL;
  3647. goto end;
  3648. }
  3649. }//END FOR ELSE
  3650. }
  3651. }// END FOR CHAdeMO_QUANTITY
  3652. }
  3653. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3654. {
  3655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3656. {
  3657. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3658. }
  3659. else
  3660. {
  3661. tempIndex = connectorIdInt -1;
  3662. }
  3663. for (int index = 0; index < CCS_QUANTITY; index++)
  3664. {
  3665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3666. {
  3667. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3668. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3669. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3670. {
  3671. //Reserved
  3672. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3673. }
  3674. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3675. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3676. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3677. {
  3678. //Reserved
  3679. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3680. result = FAIL;
  3681. goto end;
  3682. }
  3683. else
  3684. {
  3685. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3686. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3687. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3688. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3689. {
  3690. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3691. result = FAIL;
  3692. goto end;
  3693. }
  3694. }// END FOR ELSE
  3695. }
  3696. }// END FOR CCS_QUANTITY
  3697. }
  3698. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3699. {
  3700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3701. {
  3702. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3703. }
  3704. else
  3705. {
  3706. tempIndex = connectorIdInt -1;
  3707. }
  3708. for (int index = 0; index < GB_QUANTITY; index++)
  3709. {
  3710. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3711. {
  3712. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3713. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3714. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3715. {
  3716. //Reserved
  3717. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3718. }
  3719. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3720. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3721. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3722. {
  3723. //Reserved
  3724. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3725. result = FAIL;
  3726. goto end;
  3727. }
  3728. else
  3729. {
  3730. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3731. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3732. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3733. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3734. {
  3735. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3736. result = FAIL;
  3737. goto end;
  3738. }
  3739. }// END FOR ELSE
  3740. }
  3741. } // END FOR GB_QUANTITY
  3742. }
  3743. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3744. {
  3745. tempIndex = connectorIdInt -1;
  3746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3747. {
  3748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3749. {
  3750. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3751. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3752. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3753. {
  3754. //Reserved
  3755. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3756. }
  3757. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3758. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3759. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3760. {
  3761. //Reserved
  3762. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3763. result = FAIL;
  3764. goto end;
  3765. }
  3766. else
  3767. {
  3768. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3769. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3770. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3771. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3772. {
  3773. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3774. result = FAIL;
  3775. goto end;
  3776. }
  3777. }// END FOR ELSE
  3778. }
  3779. } // END FOR GB_QUANTITY
  3780. }
  3781. else
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3784. {
  3785. tempIndex = 2;
  3786. }
  3787. else
  3788. {
  3789. tempIndex = connectorIdInt -1;
  3790. }
  3791. for (int index = 0; index < AC_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3794. {
  3795. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3796. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3797. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3798. {
  3799. //Reserved
  3800. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3801. }
  3802. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3803. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3804. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3805. {
  3806. //Reserved
  3807. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3808. result = FAIL;
  3809. goto end;
  3810. }
  3811. else
  3812. {
  3813. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3814. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3815. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3816. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3817. {
  3818. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3819. result = FAIL;
  3820. goto end;
  3821. }
  3822. }//END FOR ELSE
  3823. }
  3824. }// END FOR AC_QUANTITY
  3825. }
  3826. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3827. {
  3828. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3829. {
  3830. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3831. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3832. {
  3833. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3834. system(cmdBuf);
  3835. }
  3836. }
  3837. else
  3838. {
  3839. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3840. result = FAIL;
  3841. }
  3842. }
  3843. end:
  3844. if(result == PASS)
  3845. {
  3846. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3847. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3848. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3849. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3850. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3851. }
  3852. }
  3853. void CheckSystemValue(void)
  3854. {
  3855. char filenmae[100]={0};
  3856. char str[100]={0};
  3857. int tempIndex = 0;
  3858. //===============================
  3859. // send Heartbeat
  3860. //===============================
  3861. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3862. {
  3863. //parameter for test
  3864. sendHeartbeatRequest(0);
  3865. //==============================================
  3866. // Reset Waiting Time
  3867. //==============================================
  3868. HeartBeatWithNOResponse += 2;
  3869. }
  3870. //===============================
  3871. // Credit deduct report
  3872. //===============================
  3873. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3874. {
  3875. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3876. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3877. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3878. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3879. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3880. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3881. }
  3882. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3883. {
  3884. OCPP_query_deduct_info();
  3885. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3886. }
  3887. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3888. {
  3889. // ClockAlign MeterValue
  3890. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3891. {
  3892. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3893. {
  3894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3895. {
  3896. tempIndex = ((gun_index==2) ? 1: 0);
  3897. }
  3898. else
  3899. {
  3900. tempIndex = gun_index;
  3901. }
  3902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3903. {
  3904. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3905. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3906. {
  3907. reqClockAlignMeter[gun_index] = 1;
  3908. }
  3909. }// End for CHAdeMO
  3910. }
  3911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3912. {
  3913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3914. {
  3915. tempIndex = ((gun_index==2) ? 1: 0);
  3916. }
  3917. else
  3918. {
  3919. tempIndex = gun_index;
  3920. }
  3921. for (int index = 0; index < CCS_QUANTITY; index++)
  3922. {
  3923. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3924. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3925. {
  3926. reqClockAlignMeter[gun_index] = 1;
  3927. }
  3928. } // End for CCS
  3929. }
  3930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3931. {
  3932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3933. {
  3934. tempIndex = ((gun_index==2) ? 1: 0);
  3935. }
  3936. else
  3937. {
  3938. tempIndex = gun_index;
  3939. }
  3940. for (int index = 0; index < GB_QUANTITY; index++)
  3941. {
  3942. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3943. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3944. {
  3945. reqClockAlignMeter[gun_index] = 1;
  3946. }
  3947. }// End for GB
  3948. }
  3949. else if(gunType[gun_index] == GUN_TYPE_DO)
  3950. {
  3951. tempIndex = gun_index;
  3952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3953. {
  3954. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3955. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3956. {
  3957. reqClockAlignMeter[gun_index] = 1;
  3958. }
  3959. }
  3960. }
  3961. else
  3962. {
  3963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3964. {
  3965. tempIndex = 2;
  3966. }
  3967. else
  3968. {
  3969. tempIndex = gun_index;
  3970. }
  3971. for (int index = 0; index < AC_QUANTITY; index++)
  3972. {
  3973. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3974. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3975. {
  3976. reqClockAlignMeter[gun_index] = 1;
  3977. }
  3978. }//End for AC
  3979. }
  3980. }
  3981. }
  3982. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3983. {
  3984. //==========================================
  3985. // Check remote start without connector id
  3986. //==========================================
  3987. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3988. {
  3989. int connectorIdInt = -1;
  3990. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3991. {
  3992. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3993. {
  3994. connectorIdInt = (gun_index+1);
  3995. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3996. checkRemoteStart(connectorIdInt);
  3997. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3998. break;
  3999. }
  4000. }
  4001. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4002. {
  4003. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4004. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4005. }
  4006. }
  4007. //==========================================
  4008. // csu trigger DataTransferReq
  4009. //==========================================
  4010. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4011. {
  4012. sendDataTransferRequest(gun_index);
  4013. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4014. }
  4015. //===============================
  4016. // CSU Trigger Authorize Request
  4017. //===============================
  4018. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4019. {
  4020. sendAuthorizeRequest(0);
  4021. authorizeRetryTimes = authorizeRetryTimes + 1;
  4022. if(authorizeRetryTimes < 3)
  4023. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4024. }
  4025. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4026. {
  4027. authorizeRetryTimes = 0;
  4028. SetOcppConnStatus(FALSE);
  4029. server_sign = FALSE;
  4030. }
  4031. 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))
  4032. {
  4033. sendAuthorizeRequest(0);
  4034. }
  4035. //==============================================
  4036. // Charger start transaction
  4037. //==============================================
  4038. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4039. {
  4040. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4041. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4042. sendStartTransactionRequest(gun_index);
  4043. refreshStartTimer(&clientTime.StartTransaction);
  4044. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4045. //storeTempStopTransaction(gun_index);
  4046. }
  4047. //==============================================
  4048. // Charger stop transaction
  4049. //==============================================
  4050. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4051. {
  4052. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4053. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4054. sendStopTransactionRequest(gun_index);
  4055. refreshStartTimer(&clientTime.StopTransaction);
  4056. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4057. }
  4058. //==============================================
  4059. // Charger status report
  4060. //==============================================
  4061. //--- Check Mode Change ---//
  4062. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4063. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4064. {
  4065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4066. {
  4067. tempIndex = ((gun_index==2) ? 1: 0);
  4068. }
  4069. else
  4070. {
  4071. tempIndex = gun_index;
  4072. }
  4073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4074. {
  4075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4076. {
  4077. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4078. {
  4079. // Sent unplug message for California pricing logic
  4080. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4081. {
  4082. uint8_t ts[20];
  4083. getNowDatetime(ts);
  4084. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4085. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4086. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4087. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4088. }
  4089. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4090. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4091. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4092. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4093. {
  4094. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4095. if((access(filenmae,F_OK))!=-1)
  4096. {
  4097. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4098. sprintf(str,"rm -f %s",filenmae);
  4099. system(str);
  4100. }
  4101. }
  4102. }
  4103. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4104. #if 1 // for TempStopTransaction
  4105. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4106. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4107. {
  4108. checkTempStopTransaction(gun_index);
  4109. }
  4110. #endif
  4111. }
  4112. }
  4113. }
  4114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4117. {
  4118. tempIndex = ((gun_index==2) ? 1: 0);
  4119. }
  4120. else
  4121. {
  4122. tempIndex = gun_index;
  4123. }
  4124. for (int index = 0; index < CCS_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4127. {
  4128. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4129. {
  4130. // Sent unplug message for California pricing logic
  4131. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4132. {
  4133. uint8_t ts[20];
  4134. getNowDatetime(ts);
  4135. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4138. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4139. }
  4140. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4141. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4142. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4143. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4144. {
  4145. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4146. if((access(filenmae,F_OK))!=-1)
  4147. {
  4148. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4149. sprintf(str,"rm -f %s",filenmae);
  4150. system(str);
  4151. }
  4152. }
  4153. }
  4154. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4155. #if 1 // for TempStopTransaction
  4156. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4157. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4158. {
  4159. checkTempStopTransaction(gun_index);
  4160. }
  4161. #endif
  4162. }
  4163. }
  4164. }
  4165. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4166. {
  4167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4168. {
  4169. tempIndex = ((gun_index==2) ? 1: 0);
  4170. }
  4171. else
  4172. {
  4173. tempIndex = gun_index;
  4174. }
  4175. for (int index = 0; index < GB_QUANTITY; index++)
  4176. {
  4177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4178. {
  4179. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4180. {
  4181. // Sent unplug message for California pricing logic
  4182. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4183. {
  4184. uint8_t ts[20];
  4185. getNowDatetime(ts);
  4186. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4188. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4189. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4190. }
  4191. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4192. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4193. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4194. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4195. {
  4196. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4197. if((access(filenmae,F_OK))!=-1)
  4198. {
  4199. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4200. sprintf(str,"rm -f %s",filenmae);
  4201. system(str);
  4202. }
  4203. }
  4204. }
  4205. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4206. #if 1 // for TempStopTransaction
  4207. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4208. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4209. {
  4210. checkTempStopTransaction(gun_index);
  4211. }
  4212. #endif
  4213. }
  4214. }
  4215. }
  4216. else if(gunType[gun_index] == GUN_TYPE_DO)
  4217. {
  4218. tempIndex = gun_index;
  4219. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4220. {
  4221. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4222. {
  4223. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4224. {
  4225. // Sent unplug message for California pricing logic
  4226. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4227. {
  4228. uint8_t ts[20];
  4229. getNowDatetime(ts);
  4230. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4231. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4232. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4233. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4234. }
  4235. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4236. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4237. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4238. 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
  4239. {
  4240. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4241. if((access(filenmae,F_OK))!=-1)
  4242. {
  4243. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4244. sprintf(str,"rm -f %s",filenmae);
  4245. system(str);
  4246. }
  4247. }
  4248. }
  4249. 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);
  4250. #if 1 // for TempStopTransaction
  4251. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4252. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4253. {
  4254. checkTempStopTransaction(gun_index);
  4255. }
  4256. #endif
  4257. }
  4258. }
  4259. }
  4260. else
  4261. {
  4262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4263. {
  4264. tempIndex = 2;
  4265. }
  4266. else
  4267. {
  4268. tempIndex = gun_index;
  4269. }
  4270. for (int index = 0; index < AC_QUANTITY; index++)
  4271. {
  4272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4273. {
  4274. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4275. {
  4276. // Sent unplug message for California pricing logic
  4277. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4278. {
  4279. uint8_t ts[20];
  4280. getNowDatetime(ts);
  4281. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4282. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4283. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4284. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4285. }
  4286. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4287. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4288. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4289. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4290. {
  4291. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4292. if((access(filenmae,F_OK))!=-1)
  4293. {
  4294. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4295. sprintf(str,"rm -f %s",filenmae);
  4296. system(str);
  4297. }
  4298. }
  4299. }
  4300. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4301. #if 1 // for TempStopTransaction
  4302. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4303. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4304. {
  4305. checkTempStopTransaction(gun_index);
  4306. }
  4307. #endif
  4308. }
  4309. }// END
  4310. }
  4311. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4312. (
  4313. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4314. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4315. )
  4316. )
  4317. {
  4318. if(SystemInitial > 0)
  4319. SystemInitial -= 1;
  4320. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4321. sendStatusNotificationRequest(gun_index);
  4322. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4323. }
  4324. //==============================================
  4325. // TCCI reader status report
  4326. //==============================================
  4327. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4328. {
  4329. reportReaderStatus(gun_index);
  4330. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4331. }
  4332. //==============================================
  4333. // CSU Trigger Smart Charging Profile
  4334. //==============================================
  4335. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4336. {
  4337. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4338. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4339. }
  4340. //==============================================
  4341. // Meter report
  4342. //==============================================
  4343. // Trigger MeterValue
  4344. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4345. {
  4346. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4347. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4348. }
  4349. // Clock-aligned Meter value
  4350. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4351. {
  4352. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4353. reqClockAlignMeter[gun_index] = 0;
  4354. }
  4355. // Sample period MeterValue
  4356. 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))))
  4357. {
  4358. //check Transaction active
  4359. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4360. {
  4361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4362. {
  4363. tempIndex = ((gun_index==2) ? 1: 0);
  4364. }
  4365. else
  4366. {
  4367. tempIndex = gun_index;
  4368. }
  4369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4370. {
  4371. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4372. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4373. {
  4374. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4375. {
  4376. reqSampleMeter[gun_index] = 1;
  4377. }
  4378. }
  4379. }// End for CHAdeMO
  4380. }
  4381. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4382. {
  4383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4384. {
  4385. tempIndex = ((gun_index==2) ? 1: 0);
  4386. }
  4387. else
  4388. {
  4389. tempIndex = gun_index;
  4390. }
  4391. for (int index = 0; index < CCS_QUANTITY; index++)
  4392. {
  4393. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4394. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4395. {
  4396. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4397. {
  4398. reqSampleMeter[gun_index] = 1;
  4399. }
  4400. }
  4401. } // End for CCS
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < GB_QUANTITY; index++)
  4414. {
  4415. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4416. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4417. {
  4418. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4419. {
  4420. reqSampleMeter[gun_index] = 1;
  4421. }
  4422. }
  4423. }// End for GB
  4424. }
  4425. else if(gunType[gun_index] == GUN_TYPE_DO)
  4426. {
  4427. tempIndex = gun_index;
  4428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4429. {
  4430. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4431. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4432. {
  4433. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4434. {
  4435. reqSampleMeter[gun_index] = 1;
  4436. }
  4437. }
  4438. }
  4439. }
  4440. else
  4441. {
  4442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4443. {
  4444. tempIndex = 2;
  4445. }
  4446. else
  4447. {
  4448. tempIndex = gun_index;
  4449. }
  4450. for (int index = 0; index < AC_QUANTITY; index++)
  4451. {
  4452. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4453. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4454. {
  4455. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4456. {
  4457. reqSampleMeter[gun_index] = 1;
  4458. }
  4459. }
  4460. }//End for AC
  4461. }
  4462. if(reqSampleMeter[gun_index] == 1)
  4463. {
  4464. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4465. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4466. //storeTempStopTransaction(gun_index);
  4467. reqSampleMeter[gun_index] = 0;
  4468. }
  4469. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4470. }
  4471. //==============================================
  4472. // Check Connector reserved
  4473. //==============================================
  4474. //===============================
  4475. // Check if Reserve is expired
  4476. //===============================
  4477. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4478. {
  4479. double diff_t;
  4480. struct tm tp;
  4481. // current time
  4482. time_t t = time(NULL);
  4483. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4484. tp.tm_isdst = -1;
  4485. time_t utc = mktime(&tp);
  4486. diff_t = difftime(utc, t);
  4487. if(diff_t <= 0)
  4488. {
  4489. DEBUG_INFO("reserve expired.\n");
  4490. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4491. }
  4492. }//END OF Check if Reserve is expired
  4493. //==========================================
  4494. // csu trigger FirmwareStatusNotificationReq
  4495. //==========================================
  4496. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4497. {
  4498. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4499. }
  4500. //==========================================
  4501. // csu trigger DiagnosticsStatusNotificationReq
  4502. //==========================================
  4503. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4504. {
  4505. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4506. }
  4507. //==========================================
  4508. // csu trigger CancelReservationConf
  4509. //==========================================
  4510. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4511. {
  4512. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4513. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4514. }
  4515. //==========================================
  4516. // csu trigger ChangeAvailabilityConf
  4517. //==========================================
  4518. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4519. {
  4520. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4521. }
  4522. //==========================================
  4523. // csu trigger UnlockConnectorConf
  4524. //==========================================
  4525. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4526. {
  4527. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4528. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4529. }
  4530. //==========================================
  4531. // csu trigger ReserveNowConf
  4532. //==========================================
  4533. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4534. {
  4535. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4536. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4537. }
  4538. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4539. {
  4540. sendSignCertificateRequest();
  4541. }
  4542. }
  4543. }
  4544. //==========================================
  4545. // send request routine
  4546. //==========================================
  4547. int sendAuthorizeRequest(int gun_index)
  4548. {
  4549. mtrace();
  4550. int result = FAIL;
  4551. char message[100]={0};
  4552. char guid[37];
  4553. char tempdata[65]={0};
  4554. DEBUG_INFO("sendAuthorizeRequest...\n");
  4555. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4556. //Local Authorize
  4557. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4558. {
  4559. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4560. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4561. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4562. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4563. result = PASS;
  4564. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4565. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4566. authorizeRetryTimes = 0;
  4567. return result;
  4568. }
  4569. 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))||
  4570. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4571. {
  4572. // Query from cache
  4573. DEBUG_INFO("Authorize from cache.\n");
  4574. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4575. // Query from list
  4576. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4577. {
  4578. DEBUG_INFO("Authorize from list.\n");
  4579. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4580. }
  4581. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4582. {
  4583. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4584. {
  4585. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4586. }
  4587. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4588. {
  4589. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4590. }
  4591. if(!GetOcppConnStatus())
  4592. {
  4593. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4594. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4595. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4596. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4597. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4598. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4599. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4600. authorizeRetryTimes = 0;
  4601. return result;
  4602. }
  4603. }
  4604. else
  4605. {
  4606. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4607. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4608. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4609. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4610. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4611. else
  4612. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4613. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4614. result = PASS;
  4615. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4616. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4617. authorizeRetryTimes = 0;
  4618. return result;
  4619. }
  4620. }
  4621. //initialize struct Authorize
  4622. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4623. //get data from shared memory
  4624. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4625. random_uuid(guid);
  4626. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4627. LWS_Send(message);
  4628. sprintf(tempdata, "Authorize,%d", gun_index);
  4629. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4630. {
  4631. result = PASS;
  4632. DEBUG_INFO("Authorize mapItem pass\n");
  4633. }
  4634. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4635. return result;
  4636. }
  4637. int sendBootNotificationRequest(void)
  4638. {
  4639. mtrace();
  4640. int result = FAIL;
  4641. char message[500]={0}, payload[700]={0};
  4642. char guid[37]={0};
  4643. char tempdata[65]={0};
  4644. // Fill BootNotification fields
  4645. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4646. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4647. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4648. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4649. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4650. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4651. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4652. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4653. ShmOCPP16DataPH->ChargeBoxId
  4654. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4655. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4656. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4657. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4658. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4659. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4660. random_uuid(guid);
  4661. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4662. LWS_Send(message);
  4663. sprintf(tempdata, "BootNotification,0");
  4664. 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*/)
  4665. {
  4666. result = PASS;
  4667. }
  4668. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4669. strcpy(queuedata,message);
  4670. return result;
  4671. }
  4672. int sendDataTransferRequest(int gun_index)
  4673. {
  4674. mtrace();
  4675. char message[1000]={0};
  4676. char guid[37]={0};
  4677. char tempdata[65]={0};
  4678. int result = FAIL;
  4679. random_uuid(guid);
  4680. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4681. MESSAGE_TYPE_CALL,
  4682. guid,
  4683. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4684. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4685. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4686. LWS_Send(message);
  4687. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4688. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4689. {
  4690. result = PASS;
  4691. DEBUG_INFO("DataTransfer mapItem pass\n");
  4692. }
  4693. return result;
  4694. }
  4695. int sendDiagnosticsStatusNotificationRequest(char *status)
  4696. {
  4697. mtrace();
  4698. int result = FAIL;
  4699. char message[110]={0};
  4700. char guid[37]={0};
  4701. char tempdata[65]={0};
  4702. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4703. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4704. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4705. random_uuid(guid);
  4706. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4707. LWS_SendNow(message);
  4708. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4709. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4710. {
  4711. result = PASS;
  4712. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4713. }
  4714. //#ifdef SystemLogMessage
  4715. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4716. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4717. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4718. //#endif
  4719. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4720. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4721. //record status
  4722. if(strcmp(status,"Idle")==0)
  4723. {
  4724. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4725. }
  4726. else if(strcmp(status,"Uploaded")==0)
  4727. {
  4728. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4729. }
  4730. else if(strcmp(status,"UploadFailed")==0)
  4731. {
  4732. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4733. }
  4734. else if(strcmp(status,"Uploading")==0)
  4735. {
  4736. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4737. }
  4738. return result;
  4739. }
  4740. int sendFirmwareStatusNotificationRequest(char *status)
  4741. {
  4742. mtrace();
  4743. int result = FAIL;
  4744. char message[110]={0};
  4745. char guid[37]={0};
  4746. char tempdata[65]={0};
  4747. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4748. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4749. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4750. random_uuid(guid);
  4751. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4752. LWS_SendNow(message);
  4753. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4754. 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*/)
  4755. {
  4756. result = PASS;
  4757. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4758. }
  4759. //#ifdef SystemLogMessage
  4760. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4761. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4762. //#endif
  4763. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4764. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4765. //record status
  4766. if(strcmp(status,"Downloaded")==0)
  4767. {
  4768. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4769. }
  4770. else if(strcmp(status,"DownloadFailed")==0)
  4771. {
  4772. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4773. }
  4774. else if(strcmp(status,"Downloading")==0)
  4775. {
  4776. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4777. }
  4778. else if(strcmp(status,"Idle")==0)
  4779. {
  4780. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4781. }
  4782. else if(strcmp(status,"InstallationFailed")==0)
  4783. {
  4784. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4785. }
  4786. else if(strcmp(status,"Installing")==0)
  4787. {
  4788. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4789. }
  4790. else if(strcmp(status,"Installed")==0)
  4791. {
  4792. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4793. }
  4794. return result;
  4795. }
  4796. int sendHeartbeatRequest(int gun_index)
  4797. {
  4798. mtrace();
  4799. int result = FAIL;
  4800. char message[80]={0};
  4801. char guid[37]={0};
  4802. char tempdata[65]={0};
  4803. random_uuid(guid);
  4804. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4805. , MESSAGE_TYPE_CALL
  4806. , guid );
  4807. LWS_Send(message);
  4808. sprintf(tempdata, "Heartbeat,%d", 0);
  4809. 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*/)
  4810. {
  4811. result = PASS;
  4812. }
  4813. return result;
  4814. }
  4815. int sendStartTransactionRequest(int gun_index)
  4816. {
  4817. mtrace();
  4818. int result = FAIL;
  4819. char message[250]={0};
  4820. char guid[37]={0};
  4821. struct timeval tmnow;
  4822. struct tm *tm;
  4823. char buf[28];//, usec_buf[6];
  4824. char tempdata[65]={0};
  4825. int tempIndex = 0;
  4826. DEBUG_INFO("sendStartTransactionRequest...\n");
  4827. gettimeofday(&tmnow, NULL);
  4828. time_t t;
  4829. t = time(NULL);
  4830. /*UTC time and date*/
  4831. tm = gmtime(&t);
  4832. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4833. #if 0 // remove temporally
  4834. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4835. strcat(buf,".");
  4836. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4837. strcat(buf,usec_buf);
  4838. #endif
  4839. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4840. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4841. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4842. // clear StartTransaction Response
  4843. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4844. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4845. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4846. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4847. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4848. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4849. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4850. {
  4851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4852. {
  4853. tempIndex = ((gun_index==2) ? 1: 0);
  4854. }
  4855. else
  4856. {
  4857. tempIndex = gun_index;
  4858. }
  4859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4860. {
  4861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4862. {
  4863. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4864. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4865. }
  4866. }
  4867. }
  4868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4869. {
  4870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4871. {
  4872. tempIndex = ((gun_index==2) ? 1: 0);
  4873. }
  4874. else
  4875. {
  4876. tempIndex = gun_index;
  4877. }
  4878. for (int index = 0; index < CCS_QUANTITY; index++)
  4879. {
  4880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4881. {
  4882. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4883. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4884. }
  4885. }
  4886. }
  4887. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4888. {
  4889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4890. {
  4891. tempIndex = ((gun_index==2) ? 1: 0);
  4892. }
  4893. else
  4894. {
  4895. tempIndex = gun_index;
  4896. }
  4897. for (int index = 0; index < GB_QUANTITY; index++)
  4898. {
  4899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4900. {
  4901. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4902. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4903. }
  4904. }
  4905. }
  4906. else if(gunType[gun_index] == GUN_TYPE_DO)
  4907. {
  4908. tempIndex = gun_index;
  4909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4910. {
  4911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4912. {
  4913. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4914. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4915. }
  4916. }
  4917. }
  4918. else
  4919. {
  4920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4921. {
  4922. tempIndex = 2;
  4923. }
  4924. else
  4925. {
  4926. tempIndex = gun_index;
  4927. }
  4928. for (int index = 0; index < AC_QUANTITY; index++)
  4929. {
  4930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4931. {
  4932. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4933. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4934. }
  4935. }
  4936. }
  4937. random_uuid(guid);
  4938. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4939. {
  4940. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4941. , gun_index +1
  4942. , MESSAGE_TYPE_CALL
  4943. , guid
  4944. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4945. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4946. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4947. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4948. }
  4949. else
  4950. {
  4951. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4952. , gun_index +1
  4953. , MESSAGE_TYPE_CALL
  4954. , guid
  4955. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4956. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4957. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4958. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4959. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4960. }
  4961. #if 1
  4962. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4963. 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*/)
  4964. {
  4965. result = PASS;
  4966. }
  4967. #endif
  4968. strcpy(queuedata, message);
  4969. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4970. OCPP_insert_transaction_msg(YES, queuedata);
  4971. return result;
  4972. }
  4973. int sendStatusNotificationRequest(int gun_index)
  4974. {
  4975. mtrace();
  4976. int result = FAIL;
  4977. char message[600]={0};
  4978. char guid[37];
  4979. int currentStatus = 0;
  4980. struct timeval tmnow;
  4981. struct tm *tm;
  4982. char buf[28];//, usec_buf[6];
  4983. char tempdata[65]={0};
  4984. int tempIndex = 0;
  4985. uint8_t isStateChanged = TRUE;
  4986. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4987. gettimeofday(&tmnow, NULL);
  4988. time_t t;
  4989. t = time(NULL);
  4990. /*UTC time and date*/
  4991. tm = gmtime(&t);
  4992. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4993. #if 0 // remove temporally
  4994. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4995. strcat(buf,".");
  4996. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4997. strcat(buf,usec_buf);
  4998. #endif
  4999. //printf("%s",buf);
  5000. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5001. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5002. // it's option
  5003. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5004. /*
  5005. enum _SYSTEM_STATUS
  5006. {
  5007. S_BOOTING = 0,
  5008. S_IDLE, = 1
  5009. S_AUTHORIZING, =2
  5010. S_REASSIGN_CHECK, =3
  5011. S_REASSIGN, =4
  5012. S_PRECHARGE, =5
  5013. S_PREPARING_FOR_EV, =6
  5014. S_PREPARING_FOR_EVSE, =7
  5015. S_CHARGING, =8
  5016. S_TERMINATING, =9
  5017. S_COMPLETE, =10
  5018. S_ALARM, =11
  5019. S_FAULT =12
  5020. }
  5021. */
  5022. //check Transaction active
  5023. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5024. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5025. {
  5026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5027. {
  5028. tempIndex = ((gun_index==2) ? 1: 0);
  5029. }
  5030. else
  5031. {
  5032. tempIndex = gun_index;
  5033. }
  5034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5035. {
  5036. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5037. {
  5038. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5039. {
  5040. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5041. {
  5042. currentStatus = Preparing; //OCPP Status: Preparing
  5043. }
  5044. else
  5045. {
  5046. currentStatus = Available; //OCPP Status: Available
  5047. }
  5048. }
  5049. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5050. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5051. ) //S_PRECHARGE
  5052. {
  5053. currentStatus = Preparing; //OCPP Status: Preparing
  5054. }
  5055. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5056. {
  5057. currentStatus = Charging; //OCPP Status: Charging
  5058. }
  5059. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5060. {
  5061. currentStatus = Finishing; //OCPP Status: Finishing
  5062. }
  5063. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5064. {
  5065. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5066. }
  5067. 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
  5068. {
  5069. currentStatus = Unavailable; //OCPP Status: Unavailable
  5070. }
  5071. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5072. {
  5073. currentStatus = Faulted; //OCPP Status: Faulted
  5074. }
  5075. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5076. {
  5077. currentStatus = Reserved; //OCPP Status: Reserved
  5078. }
  5079. } //end of the same index
  5080. }//end of for CHAdeMO_QUANTITY
  5081. }
  5082. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5083. {
  5084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5085. {
  5086. tempIndex = ((gun_index==2) ? 1: 0);
  5087. }
  5088. else
  5089. {
  5090. tempIndex = gun_index;
  5091. }
  5092. for (int index = 0; index < CCS_QUANTITY; index++)
  5093. {
  5094. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5095. {
  5096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5097. {
  5098. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5099. {
  5100. currentStatus = Preparing; //OCPP Status: Preparing
  5101. }
  5102. else
  5103. {
  5104. currentStatus = Available; //OCPP Status: Available
  5105. }
  5106. }
  5107. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5108. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5109. ) //S_PRECHARGE
  5110. {
  5111. currentStatus = Preparing; //OCPP Status: Preparing
  5112. }
  5113. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5114. {
  5115. currentStatus = Charging; //OCPP Status: Charging
  5116. }
  5117. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5118. {
  5119. currentStatus = Finishing; //OCPP Status: Finishing
  5120. }
  5121. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5122. {
  5123. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5124. }
  5125. 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
  5126. {
  5127. currentStatus = Unavailable; //OCPP Status : Unavailable
  5128. }
  5129. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5130. {
  5131. currentStatus = Faulted; //OCPP Status: Faulted
  5132. }
  5133. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5134. {
  5135. currentStatus = Reserved; //OCPP Status: Reserved
  5136. }
  5137. } //end of the same index
  5138. } // end of for CCS_QUANTITY
  5139. }
  5140. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5141. {
  5142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5143. {
  5144. tempIndex = ((gun_index==2) ? 1: 0);
  5145. }
  5146. else
  5147. {
  5148. tempIndex = gun_index;
  5149. }
  5150. for (int index = 0; index < GB_QUANTITY; index++)
  5151. {
  5152. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5153. {
  5154. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5155. {
  5156. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5157. {
  5158. currentStatus = Preparing; //OCPP Status: Preparing
  5159. }
  5160. else
  5161. {
  5162. currentStatus = Available; //OCPP Status: Available
  5163. }
  5164. }
  5165. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5166. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5167. ) //S_PRECHARGE
  5168. {
  5169. currentStatus = Preparing; //OCPP Status: Preparing
  5170. }
  5171. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5172. {
  5173. currentStatus = Charging; //OCPP Status: Charging
  5174. }
  5175. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5176. {
  5177. currentStatus = Finishing; //OCPP Status: Finishing
  5178. }
  5179. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5180. {
  5181. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5182. }
  5183. 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
  5184. {
  5185. currentStatus = Unavailable; //OCPP Status: Unavailable
  5186. }
  5187. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5188. {
  5189. currentStatus = Faulted; //OCPP Status: Faulted
  5190. }
  5191. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5192. {
  5193. currentStatus = Reserved; //OCPP Status: Reserved
  5194. }
  5195. } //end of the same index
  5196. } // end of for GB_QUANTITY
  5197. }
  5198. else if(gunType[gun_index] == GUN_TYPE_DO)
  5199. {
  5200. tempIndex = gun_index;
  5201. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5202. {
  5203. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5204. {
  5205. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5206. {
  5207. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5208. {
  5209. currentStatus = Preparing; //OCPP Status: Preparing
  5210. }
  5211. else
  5212. {
  5213. currentStatus = Available; //OCPP Status: Available
  5214. }
  5215. }
  5216. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5217. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5218. ) //S_PRECHARGE
  5219. {
  5220. currentStatus = Preparing; //OCPP Status: Preparing
  5221. }
  5222. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5223. {
  5224. currentStatus = Charging; //OCPP Status: Charging
  5225. }
  5226. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5227. {
  5228. currentStatus = Finishing; //OCPP Status: Finishing
  5229. }
  5230. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5231. {
  5232. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5233. }
  5234. 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
  5235. {
  5236. currentStatus = Unavailable; //OCPP Status: Unavailable
  5237. }
  5238. 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
  5239. {
  5240. currentStatus = Faulted; //OCPP Status: Faulted
  5241. }
  5242. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5243. {
  5244. currentStatus = Reserved; //OCPP Status: Reserved
  5245. }
  5246. } //end of the same index
  5247. }
  5248. }
  5249. else
  5250. {
  5251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5252. {
  5253. tempIndex = 2;
  5254. }
  5255. else
  5256. {
  5257. tempIndex = gun_index;
  5258. }
  5259. for (int index = 0; index < AC_QUANTITY; index++)
  5260. {
  5261. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5262. {
  5263. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5264. {
  5265. 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))
  5266. {
  5267. currentStatus = Preparing; //OCPP Status: Preparing
  5268. }
  5269. else
  5270. {
  5271. currentStatus = Available; //OCPP Status: Available
  5272. }
  5273. }
  5274. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5275. {
  5276. currentStatus = Preparing; //OCPP Status: Preparing
  5277. }
  5278. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5279. {
  5280. currentStatus = Charging; //OCPP Status: Charging
  5281. }
  5282. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5283. {
  5284. currentStatus = Finishing; //OCPP Status: Finishing
  5285. }
  5286. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5287. {
  5288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5289. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5290. else
  5291. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5292. }
  5293. 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
  5294. {
  5295. currentStatus = Unavailable; //OCPP Status: Unavailable
  5296. }
  5297. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5298. {
  5299. currentStatus = Faulted; //OCPP Status: Faulted
  5300. }
  5301. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5302. {
  5303. currentStatus = Reserved; //OCPP Status: Reserved
  5304. }
  5305. }//end of the same index
  5306. }//end of for AC_QUANTITY
  5307. }
  5308. //it's option
  5309. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5310. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5311. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5312. {
  5313. isStateChanged = FALSE;
  5314. }
  5315. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5316. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5317. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5318. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5319. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5320. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5321. random_uuid(guid);
  5322. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5323. , MESSAGE_TYPE_CALL
  5324. , guid
  5325. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5326. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5327. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5328. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5329. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5330. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5331. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5332. if((server_sign == TRUE) && isStateChanged)
  5333. {
  5334. LWS_Send(message);
  5335. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5336. 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*/)
  5337. {
  5338. //DEBUG_ERROR("statusNotification mapitem pass");
  5339. result = PASS;
  5340. }
  5341. }
  5342. else
  5343. {
  5344. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5345. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5346. result = PASS;
  5347. }
  5348. return result;
  5349. }
  5350. int sendStopTransactionRequest(int gun_index)
  5351. {
  5352. mtrace();
  5353. int result = FAIL;
  5354. //char message[1500]={0};
  5355. char guid[37]={0};
  5356. char tempdata[65]={0};
  5357. int tempIndex = 0;
  5358. char TempStopTransaction[256];
  5359. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5360. //int idx_sample=0;
  5361. DEBUG_INFO("sendStopTransactionRequest \n");
  5362. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5363. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5364. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5365. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5366. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5367. {
  5368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5369. {
  5370. tempIndex = ((gun_index==2) ? 1: 0);
  5371. }
  5372. else
  5373. {
  5374. tempIndex = gun_index;
  5375. }
  5376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5377. {
  5378. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5379. {
  5380. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5381. }
  5382. }// END OF CHAdeMO_QUANTITY
  5383. }
  5384. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5385. {
  5386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5387. {
  5388. tempIndex = ((gun_index==2) ? 1: 0);
  5389. }
  5390. else
  5391. {
  5392. tempIndex = gun_index;
  5393. }
  5394. for (int index = 0; index < CCS_QUANTITY; index++)
  5395. {
  5396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5397. {
  5398. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5399. }
  5400. }// END OF CCS_QUANTITY
  5401. }
  5402. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5403. {
  5404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5405. {
  5406. tempIndex = ((gun_index==2) ? 1: 0);
  5407. }
  5408. else
  5409. {
  5410. tempIndex = gun_index;
  5411. }
  5412. for (int index = 0; index < GB_QUANTITY; index++)
  5413. {
  5414. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5415. {
  5416. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5417. }
  5418. }// END OF GB_QUANTITY
  5419. }
  5420. else if(gunType[gun_index] == GUN_TYPE_DO)
  5421. {
  5422. tempIndex = gun_index;
  5423. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5424. {
  5425. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5426. {
  5427. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5428. }
  5429. }// END OF GB_QUANTITY
  5430. }
  5431. else
  5432. {
  5433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5434. {
  5435. tempIndex = 2;
  5436. }
  5437. else
  5438. {
  5439. tempIndex = gun_index;
  5440. }
  5441. for (int index = 0; index < AC_QUANTITY; index++)
  5442. {
  5443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5444. {
  5445. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5446. }
  5447. }// END OF AC_QUANTITY
  5448. }
  5449. //====================================== Stop Transaction Time =====================================================
  5450. struct timeval tmnow;
  5451. struct tm *tm;
  5452. char buf[28];//, usec_buf[6];
  5453. gettimeofday(&tmnow, NULL);
  5454. time_t t;
  5455. t = time(NULL);
  5456. /*UTC time and date*/
  5457. tm = gmtime(&t);
  5458. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5460. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5461. random_uuid(guid);
  5462. /***********************************transactionData******************************************************/
  5463. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5465. //=================================
  5466. // Transaction_Begin
  5467. //=================================
  5468. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5469. {
  5470. //============================================ Energy.Active.Import.Interval ================================
  5471. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5472. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5474. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5475. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5476. 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))
  5477. {
  5478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5479. }
  5480. else
  5481. {
  5482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5483. }
  5484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5486. }
  5487. //=================================
  5488. // Transaction_End
  5489. //=================================
  5490. // ================================= Current.Import L1 ===============================================
  5491. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5492. {
  5493. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5494. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5495. {
  5496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5497. {
  5498. tempIndex = ((gun_index==2) ? 1: 0);
  5499. }
  5500. else
  5501. {
  5502. tempIndex = gun_index;
  5503. }
  5504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5505. {
  5506. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5507. {
  5508. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5509. }
  5510. }// End of for CHAdeMO_QUANTITY
  5511. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5512. }
  5513. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5514. {
  5515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5516. {
  5517. tempIndex = ((gun_index==2) ? 1: 0);
  5518. }
  5519. else
  5520. {
  5521. tempIndex = gun_index;
  5522. }
  5523. for (int index = 0; index < CCS_QUANTITY; index++)
  5524. {
  5525. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5526. {
  5527. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5528. }
  5529. }// End of for CCS_QUANTITY
  5530. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5531. }
  5532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5533. {
  5534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5535. {
  5536. tempIndex = ((gun_index==2) ? 1: 0);
  5537. }
  5538. else
  5539. {
  5540. tempIndex = gun_index;
  5541. }
  5542. for (int index = 0; index < GB_QUANTITY; index++)
  5543. {
  5544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5545. {
  5546. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5547. }
  5548. }// End of for GB_QUANTITY
  5549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5550. }
  5551. else if(gunType[gun_index] == GUN_TYPE_DO)
  5552. {
  5553. tempIndex = gun_index;
  5554. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5555. {
  5556. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5557. {
  5558. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5559. }
  5560. }
  5561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5562. }
  5563. else
  5564. {
  5565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5566. {
  5567. tempIndex = 2;
  5568. }
  5569. else
  5570. {
  5571. tempIndex = gun_index;
  5572. }
  5573. for (int index = 0; index < AC_QUANTITY; index++)
  5574. {
  5575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5576. {
  5577. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5578. }
  5579. }// End of for AC_QUANTITY
  5580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5581. }
  5582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5587. }
  5588. // ================================= Energy.Active.Import.Interval ==============================================
  5589. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5590. {
  5591. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5592. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5593. {
  5594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5595. {
  5596. tempIndex = ((gun_index==2) ? 1: 0);
  5597. }
  5598. else
  5599. {
  5600. tempIndex = gun_index;
  5601. }
  5602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5603. {
  5604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5605. {
  5606. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5607. }
  5608. }// END OF CHAdeMO_QUANTITY
  5609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5610. }
  5611. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5612. {
  5613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5614. {
  5615. tempIndex = ((gun_index==2) ? 1: 0);
  5616. }
  5617. else
  5618. {
  5619. tempIndex = gun_index;
  5620. }
  5621. for (int index = 0; index < CCS_QUANTITY; index++)
  5622. {
  5623. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5624. {
  5625. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5626. }
  5627. }// END OF CCS_QUANTITY
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5629. }
  5630. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5631. {
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5633. {
  5634. tempIndex = ((gun_index==2) ? 1: 0);
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. for (int index = 0; index < GB_QUANTITY; index++)
  5641. {
  5642. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5643. {
  5644. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5645. }
  5646. }// END OF GB_QUANTITY
  5647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5648. }
  5649. else if(gunType[gun_index] == GUN_TYPE_DO)
  5650. {
  5651. tempIndex = gun_index;
  5652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5653. {
  5654. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5655. {
  5656. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5657. }
  5658. }
  5659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5660. }
  5661. else
  5662. {
  5663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5664. {
  5665. tempIndex = 2;
  5666. }
  5667. else
  5668. {
  5669. tempIndex = gun_index;
  5670. }
  5671. for (int index = 0; index < AC_QUANTITY; index++)
  5672. {
  5673. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5674. {
  5675. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5676. }
  5677. }// END OF AC_QUANTITY
  5678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5679. }
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5685. }
  5686. //=================================== Power.Active.Import ==================================================
  5687. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5688. {
  5689. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5690. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5691. {
  5692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5693. {
  5694. tempIndex = ((gun_index==2) ? 1: 0);
  5695. }
  5696. else
  5697. {
  5698. tempIndex = gun_index;
  5699. }
  5700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5701. {
  5702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5703. {
  5704. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5705. }
  5706. } // End for CHAdeMO_QUANTITY
  5707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5708. }
  5709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5710. {
  5711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5712. {
  5713. tempIndex = ((gun_index==2) ? 1: 0);
  5714. }
  5715. else
  5716. {
  5717. tempIndex = gun_index;
  5718. }
  5719. for (int index = 0; index < CCS_QUANTITY; index++)
  5720. {
  5721. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5722. {
  5723. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5724. }
  5725. } // END for CCS_QUANTITY
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5727. }
  5728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5731. {
  5732. tempIndex = ((gun_index==2) ? 1: 0);
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < GB_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5741. {
  5742. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5743. }
  5744. }// END for GB_QUANTITY
  5745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5746. }
  5747. else if(gunType[gun_index] == GUN_TYPE_DO)
  5748. {
  5749. tempIndex = gun_index;
  5750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5751. {
  5752. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5753. {
  5754. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5755. }
  5756. }
  5757. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5758. }
  5759. else
  5760. {
  5761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5762. {
  5763. tempIndex = 2;
  5764. }
  5765. else
  5766. {
  5767. tempIndex = gun_index;
  5768. }
  5769. for (int index = 0; index < AC_QUANTITY; index++)
  5770. {
  5771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5772. {
  5773. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5774. }
  5775. } // END for AC_QUANTITY
  5776. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5777. }
  5778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5783. }
  5784. //============================ Voltage L1 ====================================
  5785. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5786. {
  5787. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5788. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5789. {
  5790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5791. {
  5792. tempIndex = ((gun_index==2) ? 1: 0);
  5793. }
  5794. else
  5795. {
  5796. tempIndex = gun_index;
  5797. }
  5798. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5799. {
  5800. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5801. {
  5802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5803. }
  5804. } // END OF FOR CHAdeMO_QUANTITY
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5806. }
  5807. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5808. {
  5809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5810. {
  5811. tempIndex = ((gun_index==2) ? 1: 0);
  5812. }
  5813. else
  5814. {
  5815. tempIndex = gun_index;
  5816. }
  5817. for (int index = 0; index < CCS_QUANTITY; index++)
  5818. {
  5819. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5820. {
  5821. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5822. }
  5823. } // END OF FOR CCS_QUANTITY
  5824. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5825. }
  5826. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5827. {
  5828. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5829. {
  5830. tempIndex = ((gun_index==2) ? 1: 0);
  5831. }
  5832. else
  5833. {
  5834. tempIndex = gun_index;
  5835. }
  5836. for (int index = 0; index < GB_QUANTITY; index++)
  5837. {
  5838. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5839. {
  5840. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5841. }
  5842. } // END OF FOR GB_QUANTITY
  5843. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5844. }
  5845. else if(gunType[gun_index] == GUN_TYPE_DO)
  5846. {
  5847. tempIndex = gun_index;
  5848. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5849. {
  5850. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5851. {
  5852. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5853. }
  5854. }
  5855. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5856. }
  5857. else
  5858. {
  5859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5860. {
  5861. tempIndex = 2;
  5862. }
  5863. else
  5864. {
  5865. tempIndex = gun_index;
  5866. }
  5867. for (int index = 0; index < AC_QUANTITY; index++)
  5868. {
  5869. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5870. {
  5871. 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
  5872. }
  5873. } // END OF FOR AC_QUANTITY
  5874. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5875. }
  5876. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5878. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5881. }
  5882. //====================== End SoC ================================
  5883. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5884. {
  5885. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5886. 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))
  5887. {
  5888. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5889. {
  5890. tempIndex = ((gun_index==2) ? 1: 0);
  5891. }
  5892. else
  5893. {
  5894. tempIndex = gun_index;
  5895. }
  5896. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5897. {
  5898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5899. {
  5900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5901. {
  5902. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5903. }
  5904. }
  5905. }
  5906. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5907. {
  5908. for (int index = 0; index < CCS_QUANTITY; index++)
  5909. {
  5910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5911. {
  5912. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5913. }
  5914. }
  5915. }
  5916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5917. {
  5918. for (int index = 0; index < GB_QUANTITY; index++)
  5919. {
  5920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5921. {
  5922. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5923. }
  5924. }
  5925. }
  5926. else if(gunType[gun_index] == GUN_TYPE_DO)
  5927. {
  5928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5931. {
  5932. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5933. }
  5934. }
  5935. }
  5936. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5938. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5942. } // END FOR DC CASE
  5943. }
  5944. // ================================= Current.Import L2 ===============================================
  5945. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5946. {
  5947. // AC 3 phse L2 current
  5948. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5949. {
  5950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5951. {
  5952. tempIndex = 2;
  5953. }
  5954. else
  5955. {
  5956. tempIndex = gun_index;
  5957. }
  5958. for (int index = 0; index < AC_QUANTITY; index++)
  5959. {
  5960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5961. {
  5962. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5963. }
  5964. }// End of for AC_QUANTITY
  5965. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5966. }
  5967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5972. }
  5973. // ================================= Current.Import L3 ===============================================
  5974. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5975. {
  5976. // AC 3 phse L3 current
  5977. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5978. {
  5979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5980. {
  5981. tempIndex = 2;
  5982. }
  5983. else
  5984. {
  5985. tempIndex = gun_index;
  5986. }
  5987. for (int index = 0; index < AC_QUANTITY; index++)
  5988. {
  5989. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5990. {
  5991. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5992. }
  5993. }// End of for AC_QUANTITY
  5994. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5995. }
  5996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6001. }
  6002. //============================ Voltage L2 ====================================
  6003. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6004. {
  6005. // AC 3 phse L2 voltage
  6006. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6007. {
  6008. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6009. {
  6010. tempIndex = 2;
  6011. }
  6012. else
  6013. {
  6014. tempIndex = gun_index;
  6015. }
  6016. for (int index = 0; index < AC_QUANTITY; index++)
  6017. {
  6018. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6019. {
  6020. 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
  6021. }
  6022. } // END OF FOR AC_QUANTITY
  6023. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6024. }
  6025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6030. }
  6031. //============================ Voltage L3 ====================================
  6032. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6033. {
  6034. // AC 3 phse L3 voltage
  6035. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6036. {
  6037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6038. {
  6039. tempIndex = 2;
  6040. }
  6041. else
  6042. {
  6043. tempIndex = gun_index;
  6044. }
  6045. for (int index = 0; index < AC_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6050. }
  6051. } // END OF FOR AC_QUANTITY
  6052. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6053. }
  6054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6059. }
  6060. //====================== Start SoC ================================
  6061. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6062. {
  6063. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6064. 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))
  6065. {
  6066. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6067. {
  6068. tempIndex = ((gun_index==2) ? 1: 0);
  6069. }
  6070. else
  6071. {
  6072. tempIndex = gun_index;
  6073. }
  6074. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6075. {
  6076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6077. {
  6078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6079. {
  6080. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6081. }
  6082. }
  6083. }
  6084. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6085. {
  6086. for (int index = 0; index < CCS_QUANTITY; index++)
  6087. {
  6088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6089. {
  6090. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6091. }
  6092. }
  6093. }
  6094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6095. {
  6096. for (int index = 0; index < GB_QUANTITY; index++)
  6097. {
  6098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6099. {
  6100. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6101. }
  6102. }
  6103. }
  6104. else if(gunType[gun_index] == GUN_TYPE_DO)
  6105. {
  6106. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6109. {
  6110. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6111. }
  6112. }
  6113. }
  6114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6120. } // END FOR DC CASE
  6121. }
  6122. //================================================ Message create ====================================================
  6123. json_object *StopTransaction = json_object_new_object();
  6124. json_object *transactionDatas = json_object_new_array();
  6125. json_object *sampledValues = json_object_new_array();
  6126. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6127. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6128. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6129. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6130. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6131. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6132. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6133. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6134. {
  6135. json_object *transactionData = json_object_new_object();
  6136. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6137. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6138. {
  6139. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6140. {
  6141. json_object *sampledValue = json_object_new_object();
  6142. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6143. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6144. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6145. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6146. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6147. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6148. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6149. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6150. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6151. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6152. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6153. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6154. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6155. json_object_array_add(sampledValues, sampledValue);
  6156. }
  6157. }
  6158. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6159. json_object_array_add(transactionDatas, transactionData);
  6160. }
  6161. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6162. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6163. ,MESSAGE_TYPE_CALL
  6164. ,guid
  6165. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6166. json_object_put(StopTransaction);
  6167. #if 1 // for TempStopTransaction
  6168. //Delete TempStopTransaction
  6169. if((access(TempStopTransaction,F_OK))!=-1)
  6170. {
  6171. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6172. }
  6173. #endif
  6174. #if 1
  6175. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6176. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6177. {
  6178. result = PASS;
  6179. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6180. }
  6181. #endif
  6182. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6183. OCPP_insert_transaction_msg(NO, queuedata);
  6184. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6185. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6186. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6187. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6188. {
  6189. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6190. }
  6191. //for test
  6192. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6193. return result;
  6194. }
  6195. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6196. {
  6197. mtrace();
  6198. int result = FAIL;
  6199. char guid[37]={0};
  6200. char tempdata[65]={0};
  6201. int tempIndex = 0;
  6202. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6203. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6204. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6205. //set value
  6206. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6207. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6208. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6209. -1);
  6210. random_uuid(guid);
  6211. //UTC Date time
  6212. struct timeval tmnow;
  6213. struct tm *tm;
  6214. char buf[28];//, usec_buf[6];
  6215. gettimeofday(&tmnow, NULL);
  6216. time_t t;
  6217. t = time(NULL);
  6218. /*UTC time and date*/
  6219. tm = gmtime(&t);
  6220. if(dataType == ReadingContext_Sample_Clock)
  6221. {
  6222. struct tm *tmTarget;
  6223. struct timeb tbTarget;
  6224. tbTarget.time = mktime(tm);
  6225. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6226. tmTarget = gmtime(&tbTarget.time);
  6227. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6228. }
  6229. else
  6230. {
  6231. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6232. }
  6233. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6234. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6235. //********************************(1)Current.Import L1************************************************/
  6236. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6237. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6238. (dataType == ReadingContext_Trigger))
  6239. {
  6240. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6241. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6242. {
  6243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6244. {
  6245. tempIndex = ((gun_index==2) ? 1: 0);
  6246. }
  6247. else
  6248. {
  6249. tempIndex = gun_index;
  6250. }
  6251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6252. {
  6253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6254. {
  6255. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6256. }
  6257. }
  6258. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6259. }
  6260. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6261. {
  6262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6263. {
  6264. tempIndex = ((gun_index==2) ? 1: 0);
  6265. }
  6266. else
  6267. {
  6268. tempIndex = gun_index;
  6269. }
  6270. for (int index = 0; index < CCS_QUANTITY; index++)
  6271. {
  6272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6273. {
  6274. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6275. }
  6276. }
  6277. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6278. }
  6279. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6280. {
  6281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6282. {
  6283. tempIndex = ((gun_index==2) ? 1: 0);
  6284. }
  6285. else
  6286. {
  6287. tempIndex = gun_index;
  6288. }
  6289. for (int index = 0; index < GB_QUANTITY; index++)
  6290. {
  6291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6292. {
  6293. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6294. }
  6295. }
  6296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6297. }
  6298. else if(gunType[gun_index] == GUN_TYPE_DO)
  6299. {
  6300. tempIndex = gun_index;
  6301. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6304. {
  6305. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6306. }
  6307. }
  6308. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6309. }
  6310. else
  6311. {
  6312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6313. {
  6314. tempIndex = 2;
  6315. }
  6316. else
  6317. {
  6318. tempIndex = gun_index;
  6319. }
  6320. for (int index = 0; index < AC_QUANTITY; index++)
  6321. {
  6322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6323. {
  6324. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6325. }
  6326. }
  6327. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6328. }
  6329. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6330. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6331. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6333. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6334. }
  6335. //********************************(2)Energy.Active.Import.Register ************************************************/
  6336. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6337. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6338. (dataType == ReadingContext_Trigger))
  6339. {
  6340. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6341. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6342. {
  6343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6344. {
  6345. tempIndex = ((gun_index==2) ? 1: 0);
  6346. }
  6347. else
  6348. {
  6349. tempIndex = gun_index;
  6350. }
  6351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6352. {
  6353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6354. {
  6355. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6356. }
  6357. }
  6358. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6359. }
  6360. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6361. {
  6362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6363. {
  6364. tempIndex = ((gun_index==2) ? 1: 0);
  6365. }
  6366. else
  6367. {
  6368. tempIndex = gun_index;
  6369. }
  6370. for (int index = 0; index < CCS_QUANTITY; index++)
  6371. {
  6372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6373. {
  6374. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6375. }
  6376. }
  6377. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6378. }
  6379. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6380. {
  6381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6382. {
  6383. tempIndex = ((gun_index==2) ? 1: 0);
  6384. }
  6385. else
  6386. {
  6387. tempIndex = gun_index;
  6388. }
  6389. for (int index = 0; index < GB_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6394. }
  6395. }
  6396. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6397. }
  6398. else if(gunType[gun_index] == GUN_TYPE_DO)
  6399. {
  6400. tempIndex = gun_index;
  6401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6402. {
  6403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6404. {
  6405. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6406. }
  6407. }
  6408. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6409. }
  6410. else
  6411. {
  6412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6413. {
  6414. tempIndex = 2;
  6415. }
  6416. else
  6417. {
  6418. tempIndex = gun_index;
  6419. }
  6420. for (int index = 0; index < AC_QUANTITY; index++)
  6421. {
  6422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6423. {
  6424. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6425. }
  6426. }
  6427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6428. }
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6431. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6433. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6434. }
  6435. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6436. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6437. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6438. (dataType == ReadingContext_Trigger))
  6439. {
  6440. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6441. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6442. {
  6443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6444. {
  6445. tempIndex = ((gun_index==2) ? 1: 0);
  6446. }
  6447. else
  6448. {
  6449. tempIndex = gun_index;
  6450. }
  6451. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6452. {
  6453. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6454. {
  6455. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6456. }
  6457. } // END OF FOR CHAdeMO_QUANTITY
  6458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6459. }
  6460. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6461. {
  6462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6463. {
  6464. tempIndex = ((gun_index==2) ? 1: 0);
  6465. }
  6466. else
  6467. {
  6468. tempIndex = gun_index;
  6469. }
  6470. for (int index = 0; index < CCS_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6475. }
  6476. } // END OF CCS_QUANTITY
  6477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6480. {
  6481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6482. {
  6483. tempIndex = ((gun_index==2) ? 1: 0);
  6484. }
  6485. else
  6486. {
  6487. tempIndex = gun_index;
  6488. }
  6489. for (int index = 0; index < GB_QUANTITY; index++)
  6490. {
  6491. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6492. {
  6493. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6494. }
  6495. } // END OF GB_QUANTITY
  6496. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6497. }
  6498. else if(gunType[gun_index] == GUN_TYPE_DO)
  6499. {
  6500. tempIndex = gun_index;
  6501. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6502. {
  6503. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6504. {
  6505. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6506. }
  6507. }
  6508. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6509. }
  6510. else
  6511. {
  6512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6513. {
  6514. tempIndex = 2;
  6515. }
  6516. else
  6517. {
  6518. tempIndex = gun_index;
  6519. }
  6520. for (int index = 0; index < AC_QUANTITY; index++)
  6521. {
  6522. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6523. {
  6524. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6525. }
  6526. }
  6527. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6528. }
  6529. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6531. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6534. }
  6535. //********************************(4)Power.Active.Import************************************************/
  6536. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6537. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6538. (dataType == ReadingContext_Trigger))
  6539. {
  6540. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6541. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6542. {
  6543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6544. {
  6545. tempIndex = ((gun_index==2) ? 1: 0);
  6546. }
  6547. else
  6548. {
  6549. tempIndex = gun_index;
  6550. }
  6551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6554. {
  6555. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6556. }
  6557. } // END OF FOR
  6558. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6559. }
  6560. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6561. {
  6562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6563. {
  6564. tempIndex = ((gun_index==2) ? 1: 0);
  6565. }
  6566. else
  6567. {
  6568. tempIndex = gun_index;
  6569. }
  6570. for (int index = 0; index < CCS_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6573. {
  6574. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6575. }
  6576. }
  6577. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6578. }
  6579. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6580. {
  6581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6582. {
  6583. tempIndex = ((gun_index==2) ? 1: 0);
  6584. }
  6585. else
  6586. {
  6587. tempIndex = gun_index;
  6588. }
  6589. for (int index = 0; index < GB_QUANTITY; index++)
  6590. {
  6591. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6592. {
  6593. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6594. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6595. }
  6596. }
  6597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6598. }
  6599. else if(gunType[gun_index] == GUN_TYPE_DO)
  6600. {
  6601. tempIndex = gun_index;
  6602. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6605. {
  6606. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6607. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6608. }
  6609. }
  6610. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6611. }
  6612. else
  6613. {
  6614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6615. {
  6616. tempIndex = 2;
  6617. }
  6618. else
  6619. {
  6620. tempIndex = gun_index;
  6621. }
  6622. for (int index = 0; index < AC_QUANTITY; index++)
  6623. {
  6624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6625. {
  6626. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6627. }
  6628. }
  6629. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6630. }
  6631. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6632. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6633. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6634. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6635. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6636. }
  6637. //***********************************************(5)VOLTAGE L1******************************************************/
  6638. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6639. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6640. (dataType == ReadingContext_Trigger))
  6641. {
  6642. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6643. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6644. {
  6645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6646. {
  6647. tempIndex = ((gun_index==2) ? 1: 0);
  6648. }
  6649. else
  6650. {
  6651. tempIndex = gun_index;
  6652. }
  6653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6654. {
  6655. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6656. {
  6657. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6658. }
  6659. }
  6660. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6661. }
  6662. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6663. {
  6664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6665. {
  6666. tempIndex = ((gun_index==2) ? 1: 0);
  6667. }
  6668. else
  6669. {
  6670. tempIndex = gun_index;
  6671. }
  6672. for (int index = 0; index < CCS_QUANTITY; index++)
  6673. {
  6674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6675. {
  6676. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6677. }
  6678. }
  6679. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6680. }
  6681. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6682. {
  6683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6684. {
  6685. tempIndex = ((gun_index==2) ? 1: 0);
  6686. }
  6687. else
  6688. {
  6689. tempIndex = gun_index;
  6690. }
  6691. for (int index = 0; index < GB_QUANTITY; index++)
  6692. {
  6693. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6694. {
  6695. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6696. }
  6697. }
  6698. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6699. }
  6700. else if(gunType[gun_index] == GUN_TYPE_DO)
  6701. {
  6702. tempIndex = gun_index;
  6703. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6704. {
  6705. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6706. {
  6707. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6708. }
  6709. }
  6710. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6711. }
  6712. else
  6713. {
  6714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6715. {
  6716. tempIndex = 2;
  6717. }
  6718. else
  6719. {
  6720. tempIndex = gun_index;
  6721. }
  6722. for (int index = 0; index < AC_QUANTITY; index++)
  6723. {
  6724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6725. {
  6726. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6727. }
  6728. }
  6729. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6730. }
  6731. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6732. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6733. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6734. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6735. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6736. }
  6737. //***********************************************(6)SOC******************************************************/
  6738. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6739. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6740. (dataType == ReadingContext_Trigger))
  6741. {
  6742. 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))
  6743. {
  6744. //idx_sample=5;
  6745. //sampledValue = NULL;
  6746. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6747. {
  6748. tempIndex = ((gun_index==2) ? 1: 0);
  6749. }
  6750. else
  6751. {
  6752. tempIndex = gun_index;
  6753. }
  6754. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6755. {
  6756. //tempIndex = ((gun_index==2) ? 1: 0);
  6757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6758. {
  6759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6760. {
  6761. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6762. }
  6763. }
  6764. }
  6765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6766. {
  6767. //tempIndex = ((gun_index==2) ? 1: 0);
  6768. for (int index = 0; index < CCS_QUANTITY; index++)
  6769. {
  6770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6771. {
  6772. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6773. }
  6774. }
  6775. }
  6776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6777. {
  6778. //tempIndex = ((gun_index==2) ? 1: 0);
  6779. for (int index = 0; index < GB_QUANTITY; index++)
  6780. {
  6781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6782. {
  6783. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6784. }
  6785. }
  6786. }
  6787. else if(gunType[gun_index] == GUN_TYPE_DO)
  6788. {
  6789. //tempIndex = ((gun_index==2) ? 1: 0);
  6790. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6791. {
  6792. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6793. {
  6794. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6795. }
  6796. }
  6797. }
  6798. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6799. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6800. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6801. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6802. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6803. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6804. }
  6805. }
  6806. //********************************(7)Current.Import L2************************************************/
  6807. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6808. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6809. (dataType == ReadingContext_Trigger))
  6810. {
  6811. // Only for AC 3 phase
  6812. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6813. {
  6814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6815. {
  6816. tempIndex = 2;
  6817. }
  6818. else
  6819. {
  6820. tempIndex = gun_index;
  6821. }
  6822. for (int index = 0; index < AC_QUANTITY; index++)
  6823. {
  6824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6825. {
  6826. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6827. }
  6828. }
  6829. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6830. }
  6831. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6832. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6833. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6834. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6835. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6836. }
  6837. //********************************(8)Current.Import L3************************************************/
  6838. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6839. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6840. (dataType == ReadingContext_Trigger))
  6841. {
  6842. // Only for AC 3 phase
  6843. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6844. {
  6845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6846. {
  6847. tempIndex = 2;
  6848. }
  6849. else
  6850. {
  6851. tempIndex = gun_index;
  6852. }
  6853. for (int index = 0; index < AC_QUANTITY; index++)
  6854. {
  6855. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6856. {
  6857. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6858. }
  6859. }
  6860. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6861. }
  6862. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6863. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6864. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6867. }
  6868. //***********************************************(9)VOLTAGE L2******************************************************/
  6869. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6870. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6871. (dataType == ReadingContext_Trigger))
  6872. {
  6873. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6874. {
  6875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6876. {
  6877. tempIndex = 2;
  6878. }
  6879. else
  6880. {
  6881. tempIndex = gun_index;
  6882. }
  6883. for (int index = 0; index < AC_QUANTITY; index++)
  6884. {
  6885. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6886. {
  6887. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6888. }
  6889. }
  6890. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6891. }
  6892. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6893. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6894. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6895. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6897. }
  6898. //***********************************************(10)VOLTAGE L3******************************************************/
  6899. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6900. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6901. (dataType == ReadingContext_Trigger))
  6902. {
  6903. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6904. {
  6905. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6906. {
  6907. tempIndex = 2;
  6908. }
  6909. else
  6910. {
  6911. tempIndex = gun_index;
  6912. }
  6913. for (int index = 0; index < AC_QUANTITY; index++)
  6914. {
  6915. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6916. {
  6917. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6918. }
  6919. }
  6920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6921. }
  6922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6927. }
  6928. //***********************************************(11)Current.Offered******************************************************/
  6929. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6930. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6931. (dataType == ReadingContext_Trigger))
  6932. {
  6933. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6934. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6935. {
  6936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6937. {
  6938. tempIndex = ((gun_index==2) ? 1: 0);
  6939. }
  6940. else
  6941. {
  6942. tempIndex = gun_index;
  6943. }
  6944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6945. {
  6946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6947. {
  6948. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6949. }
  6950. } // END OF FOR CHAdeMO_QUANTITY
  6951. }
  6952. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6953. {
  6954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6955. {
  6956. tempIndex = ((gun_index==2) ? 1: 0);
  6957. }
  6958. else
  6959. {
  6960. tempIndex = gun_index;
  6961. }
  6962. for (int index = 0; index < CCS_QUANTITY; index++)
  6963. {
  6964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6965. {
  6966. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6967. }
  6968. } // END OF CCS_QUANTITY
  6969. }
  6970. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6971. {
  6972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6973. {
  6974. tempIndex = ((gun_index==2) ? 1: 0);
  6975. }
  6976. else
  6977. {
  6978. tempIndex = gun_index;
  6979. }
  6980. for (int index = 0; index < GB_QUANTITY; index++)
  6981. {
  6982. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6983. {
  6984. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6985. }
  6986. } // END OF GB_QUANTITY
  6987. }
  6988. else if(gunType[gun_index] == GUN_TYPE_DO)
  6989. {
  6990. tempIndex = gun_index;
  6991. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6992. {
  6993. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6994. {
  6995. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6996. }
  6997. }
  6998. }
  6999. else
  7000. {
  7001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7002. {
  7003. tempIndex = 2;
  7004. }
  7005. else
  7006. {
  7007. tempIndex = gun_index;
  7008. }
  7009. for (int index = 0; index < AC_QUANTITY; index++)
  7010. {
  7011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7012. {
  7013. uint16_t currentOffer;
  7014. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7015. {
  7016. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7017. }
  7018. else
  7019. {
  7020. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7021. }
  7022. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7023. }
  7024. }
  7025. }
  7026. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7027. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7028. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7031. }
  7032. //***********************************************(12)Power.Offered******************************************************/
  7033. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7034. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7035. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7036. {
  7037. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7038. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7039. {
  7040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7041. {
  7042. tempIndex = ((gun_index==2) ? 1: 0);
  7043. }
  7044. else
  7045. {
  7046. tempIndex = gun_index;
  7047. }
  7048. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7049. {
  7050. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7051. {
  7052. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7053. }
  7054. } // END OF FOR CHAdeMO_QUANTITY
  7055. }
  7056. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7057. {
  7058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7059. {
  7060. tempIndex = ((gun_index==2) ? 1: 0);
  7061. }
  7062. else
  7063. {
  7064. tempIndex = gun_index;
  7065. }
  7066. for (int index = 0; index < CCS_QUANTITY; index++)
  7067. {
  7068. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7069. {
  7070. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7071. }
  7072. } // END OF CCS_QUANTITY
  7073. }
  7074. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7075. {
  7076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7077. {
  7078. tempIndex = ((gun_index==2) ? 1: 0);
  7079. }
  7080. else
  7081. {
  7082. tempIndex = gun_index;
  7083. }
  7084. for (int index = 0; index < GB_QUANTITY; index++)
  7085. {
  7086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7087. {
  7088. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7089. }
  7090. } // END OF GB_QUANTITY
  7091. }
  7092. else if(gunType[gun_index] == GUN_TYPE_DO)
  7093. {
  7094. tempIndex = gun_index;
  7095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7096. {
  7097. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7098. {
  7099. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7100. }
  7101. }
  7102. }
  7103. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7105. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7108. }
  7109. // Message create ====================================================================================================
  7110. if(TRUE)
  7111. {
  7112. json_object *MeterValueReq = json_object_new_object();
  7113. json_object *MeterValues = json_object_new_array();
  7114. json_object *sampledValues = json_object_new_array();
  7115. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7116. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7117. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7118. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7119. {
  7120. json_object *MeterValue = json_object_new_object();
  7121. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7122. {
  7123. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7124. {
  7125. json_object *sampledValue = json_object_new_object();
  7126. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7127. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7128. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7129. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7130. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7131. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7132. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7133. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7134. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7135. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7136. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7137. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7138. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7139. json_object_array_add(sampledValues, sampledValue);
  7140. }
  7141. }
  7142. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7143. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7144. json_object_array_add(MeterValues, MeterValue);
  7145. }
  7146. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7147. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7148. ,gun_index + 1
  7149. ,MESSAGE_TYPE_CALL
  7150. ,guid
  7151. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7152. json_object_put(MeterValueReq);
  7153. }
  7154. // Put request guid to hash map
  7155. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7156. 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*/)
  7157. {
  7158. result = PASS;
  7159. //DEBUG_INFO("MeterValues mapitem pass\n");
  7160. }
  7161. if((dataType != ReadingContext_Trigger) &&
  7162. (dataType != ReadingContext_Sample_Clock) &&
  7163. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7164. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7165. else
  7166. {
  7167. if(FirstHeartBeat)
  7168. LWS_Send(queuedata +2);
  7169. }
  7170. return result;
  7171. }
  7172. int sendLogStatusNotificationRequest(char *status)
  7173. {
  7174. mtrace();
  7175. int result = PASS;
  7176. char message[4096]={0};
  7177. char guid[37]={0};
  7178. char tempdata[128]={0};
  7179. json_object *LogStatusNotification = json_object_new_object();
  7180. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7181. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7182. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7183. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7184. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7185. random_uuid(guid);
  7186. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7187. json_object_put(LogStatusNotification);
  7188. LWS_Send(message);
  7189. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7190. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7191. {
  7192. result = PASS;
  7193. }
  7194. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7195. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7196. return result;
  7197. }
  7198. int sendSecurityEventNotificationRequest()
  7199. {
  7200. mtrace();
  7201. int result = PASS;
  7202. char message[4096]={0};
  7203. char guid[37]={0};
  7204. char tempdata[128]={0};
  7205. json_object *SecurityEventNotification = json_object_new_object();
  7206. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7207. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7208. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7209. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7210. random_uuid(guid);
  7211. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7212. json_object_put(SecurityEventNotification);
  7213. LWS_Send(message);
  7214. sprintf(tempdata, "SecurityEventNotification,0");
  7215. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7216. {
  7217. result = PASS;
  7218. }
  7219. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7220. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7221. return result;
  7222. }
  7223. int sendSignCertificateRequest()
  7224. {
  7225. mtrace();
  7226. int result = PASS;
  7227. char message[4096]={0};
  7228. char guid[37]={0};
  7229. char tempdata[128]={0};
  7230. json_object *SignCertificate = json_object_new_object();
  7231. DEBUG_INFO("sendSignCertificateRequest...\n");
  7232. // Read csr file content
  7233. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7234. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7235. char *line = NULL;
  7236. size_t len = 0;
  7237. while(getline(&line, &len, fp) != -1)
  7238. {
  7239. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7240. {
  7241. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7242. }
  7243. }
  7244. fclose(fp);
  7245. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7246. random_uuid(guid);
  7247. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7248. json_object_put(SignCertificate);
  7249. LWS_Send(message);
  7250. sprintf(tempdata, "SignCertificate,0");
  7251. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7252. {
  7253. result = PASS;
  7254. }
  7255. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7256. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7257. return result;
  7258. }
  7259. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7260. {
  7261. mtrace();
  7262. int result = PASS;
  7263. char message[110]={0};
  7264. char guid[37]={0};
  7265. char tempdata[65]={0};
  7266. json_object *FirmwareStatusNotification = json_object_new_object();
  7267. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7268. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7269. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7270. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7271. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7272. random_uuid(guid);
  7273. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7274. json_object_put(FirmwareStatusNotification);
  7275. LWS_Send(message);
  7276. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7277. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7278. {
  7279. result = PASS;
  7280. }
  7281. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7282. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7283. return result;
  7284. }
  7285. //==========================================
  7286. // send confirm routine
  7287. //==========================================
  7288. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7289. {
  7290. mtrace();
  7291. int result = FAIL;
  7292. char message[100]={0};
  7293. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7295. LWS_Send(message);
  7296. result = TRUE;
  7297. return result;
  7298. }
  7299. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7300. {
  7301. mtrace();
  7302. int result = FAIL;
  7303. char message[100]={0};
  7304. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7305. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7306. LWS_Send(message);
  7307. result = TRUE;
  7308. return result;
  7309. }
  7310. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7311. {
  7312. mtrace();
  7313. int result = FAIL;
  7314. char message[100]={0};
  7315. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7316. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7317. LWS_Send(message);
  7318. result = TRUE;
  7319. return result;
  7320. }
  7321. int sendClearCacheConfirmation(char *uuid,char *payload)
  7322. {
  7323. mtrace();
  7324. int result = FAIL;
  7325. char message[500]={0};
  7326. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7327. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7328. LWS_Send(message);
  7329. return result;
  7330. }
  7331. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7332. {
  7333. mtrace();
  7334. int result = FAIL;
  7335. char message[500]={0};
  7336. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7337. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7338. LWS_Send(message);
  7339. return result;
  7340. }
  7341. int sendDataTransferConfirmation(char *uuid,char *payload)
  7342. {
  7343. mtrace();
  7344. char statusStr[20]={0};
  7345. char dataStr[10]={0};
  7346. char sstr[20]={0};
  7347. int c = 0;
  7348. char *loc;
  7349. int result = FAIL;
  7350. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7351. /**********************status**************************/
  7352. loc = strstr(payload, "status");
  7353. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7354. c = 0;
  7355. while (loc[3+strlen("status")+c] != '\"')
  7356. {
  7357. sstr[c] = loc[3+strlen("status")+c];
  7358. c++;
  7359. }
  7360. sstr[c] = '\0';
  7361. strcpy(statusStr, sstr);
  7362. /**********************data**************************/
  7363. loc = strstr(payload, "data");
  7364. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7365. c = 0;
  7366. while (loc[3+strlen("data")+c] != '\"')
  7367. {
  7368. sstr[c] = loc[3+strlen("data")+c];
  7369. c++;
  7370. }
  7371. sstr[c] = '\0';
  7372. strcpy(dataStr, sstr);
  7373. return result;
  7374. }
  7375. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7376. {
  7377. mtrace();
  7378. int result = FAIL;
  7379. char message[1000]={0};
  7380. int CompositeScheduleIndex = 0;
  7381. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7382. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7383. if(nPeriod == 0)
  7384. {
  7385. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7386. {
  7387. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7388. ,MESSAGE_TYPE_CALLRESULT
  7389. ,uuid
  7390. ,payload
  7391. ,connectorIdInt);
  7392. }
  7393. else
  7394. {
  7395. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7396. ,MESSAGE_TYPE_CALLRESULT
  7397. ,uuid
  7398. ,payload
  7399. ,connectorIdInt
  7400. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7401. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7402. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7403. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7404. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7405. }
  7406. }
  7407. else
  7408. {
  7409. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7410. ,MESSAGE_TYPE_CALLRESULT
  7411. ,uuid
  7412. ,payload
  7413. ,connectorIdInt
  7414. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7415. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7416. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7417. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7418. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7419. {
  7420. if (idx_sample == 0)
  7421. {
  7422. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7423. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7424. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7425. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7426. }
  7427. else
  7428. {
  7429. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7430. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7431. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7432. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7433. }
  7434. }
  7435. sprintf(message + strlen(message), "]}}]");
  7436. }
  7437. LWS_Send(message);
  7438. result = TRUE;
  7439. return result;
  7440. }
  7441. int sendGetConfigurationConfirmation(char *uuid)
  7442. {
  7443. mtrace();
  7444. int result = FAIL;
  7445. int MaxKeySupported = 0;
  7446. int sentConfigurationNumber= 0;
  7447. int sentunConfigurationNumber= 0;
  7448. char message[1024*10]={0};
  7449. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7450. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7451. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7452. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7453. ,MESSAGE_TYPE_CALLRESULT
  7454. ,uuid );
  7455. //configuration key
  7456. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7457. {
  7458. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7459. {
  7460. if (sentConfigurationNumber == 0)
  7461. {
  7462. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7463. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7464. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7465. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7466. }
  7467. else
  7468. {
  7469. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7470. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7471. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7472. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7473. }
  7474. sentConfigurationNumber = sentConfigurationNumber + 1;
  7475. }
  7476. }
  7477. sprintf(message + strlen(message), "]");
  7478. if(UnknownKeynum != 0)
  7479. {
  7480. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7481. //unkown key
  7482. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7483. {
  7484. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7485. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7486. if(sentunConfigurationNumber == 0)
  7487. {
  7488. sprintf(message + strlen(message), "\"%s\""
  7489. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7490. }
  7491. else
  7492. {
  7493. sprintf(message + strlen(message), ",\"%s\""
  7494. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7495. }
  7496. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7497. }
  7498. sprintf(message + strlen(message), "]");
  7499. }
  7500. sprintf(message + strlen(message), "}]");
  7501. LWS_Send(message);
  7502. return result;
  7503. }
  7504. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7505. {
  7506. mtrace();
  7507. int result = FAIL;
  7508. char message[400]={0};
  7509. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7510. if(strcmp(payload,"")==0)
  7511. {
  7512. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7513. }
  7514. else
  7515. {
  7516. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7517. }
  7518. LWS_Send(message);
  7519. result = TRUE;
  7520. return result;
  7521. }
  7522. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7523. {
  7524. mtrace();
  7525. int result = FAIL;
  7526. char message[80]={0};
  7527. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7528. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7529. LWS_Send(message);
  7530. result = TRUE;
  7531. return result;
  7532. }
  7533. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7534. {
  7535. mtrace();
  7536. int result = FAIL;
  7537. char message[80]={0};
  7538. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7539. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7540. LWS_Send(message);
  7541. result = TRUE;
  7542. return result;
  7543. }
  7544. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7545. {
  7546. mtrace();
  7547. int result = FAIL;
  7548. char message[80]={0};
  7549. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7550. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7551. LWS_Send(message);
  7552. result = TRUE;
  7553. return result;
  7554. }
  7555. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7556. {
  7557. mtrace();
  7558. int result = FAIL;
  7559. char message[80]={0};
  7560. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7561. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7562. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7563. LWS_Send(message);
  7564. result = TRUE;
  7565. return result;
  7566. }
  7567. int sendResetConfirmation(char *uuid,char *payload)
  7568. {
  7569. mtrace();
  7570. int result = FAIL;
  7571. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7572. char message[80]={0};
  7573. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7574. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7575. LWS_Send(message);
  7576. result = TRUE;
  7577. return result;
  7578. }
  7579. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7580. {
  7581. mtrace();
  7582. int result = FAIL;
  7583. char message[500]={0};
  7584. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7585. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7586. LWS_Send(message);
  7587. result = TRUE;
  7588. return result;
  7589. }
  7590. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7591. {
  7592. mtrace();
  7593. int result = FAIL;
  7594. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7595. char message[80]={0};
  7596. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7597. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7598. LWS_Send(message);
  7599. result = TRUE;
  7600. return result;
  7601. }
  7602. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7603. {
  7604. mtrace();
  7605. int result = FAIL;
  7606. char message[80]={0};
  7607. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7608. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7609. LWS_Send(message);
  7610. result = TRUE;
  7611. return result;
  7612. }
  7613. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7614. {
  7615. mtrace();
  7616. int result = FAIL;
  7617. char message[80]={0};
  7618. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7619. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7620. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7621. LWS_Send(message);
  7622. result = TRUE;
  7623. return result;
  7624. }
  7625. int sendUpdateFirmwareConfirmation(char *uuid)
  7626. {
  7627. mtrace();
  7628. int result = FAIL;
  7629. char message[60]={0};
  7630. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7631. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7632. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7633. LWS_Send(message);
  7634. result = TRUE;
  7635. return result;
  7636. }
  7637. int sendCertificateSignedConfirmation(char *uuid)
  7638. {
  7639. mtrace();
  7640. int result = PASS;
  7641. char message[4096]={0};
  7642. json_object *CertificateSigned = json_object_new_object();
  7643. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7644. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7645. sprintf(message,"[%d,\"%s\",%s]"
  7646. ,MESSAGE_TYPE_CALLRESULT
  7647. ,uuid
  7648. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7649. json_object_put(CertificateSigned);
  7650. LWS_Send(message);
  7651. return result;
  7652. }
  7653. int sendDeleteCertificateConfirmation(char *uuid)
  7654. {
  7655. mtrace();
  7656. int result = PASS;
  7657. char message[4096]={0};
  7658. json_object *DeleteCertificate = json_object_new_object();
  7659. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7660. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7661. sprintf(message,"[%d,\"%s\",%s]"
  7662. ,MESSAGE_TYPE_CALLRESULT
  7663. ,uuid
  7664. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7665. json_object_put(DeleteCertificate);
  7666. LWS_Send(message);
  7667. return result;
  7668. }
  7669. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7670. {
  7671. mtrace();
  7672. int result = PASS;
  7673. char message[4096]={0};
  7674. json_object *ExtendedTriggerMessage = json_object_new_object();
  7675. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7676. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7677. sprintf(message,"[%d,\"%s\",%s]"
  7678. ,MESSAGE_TYPE_CALLRESULT
  7679. ,uuid
  7680. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7681. json_object_put(ExtendedTriggerMessage);
  7682. LWS_Send(message);
  7683. return result;
  7684. }
  7685. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7686. {
  7687. mtrace();
  7688. int result = PASS;
  7689. char message[4096]={0};
  7690. json_object *GetInstalledCertificateIds = json_object_new_object();
  7691. json_object *certificateHashDataDatas = json_object_new_array();
  7692. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7693. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7694. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7695. {
  7696. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7697. {
  7698. json_object *certificateHashData = json_object_new_object();
  7699. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7700. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7701. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7702. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7703. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7704. }
  7705. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7706. }
  7707. else
  7708. {
  7709. json_object_put(certificateHashDataDatas);
  7710. }
  7711. sprintf(message,"[%d,\"%s\",%s]"
  7712. ,MESSAGE_TYPE_CALLRESULT
  7713. ,uuid
  7714. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7715. json_object_put(GetInstalledCertificateIds);
  7716. LWS_Send(message);
  7717. return result;
  7718. }
  7719. int sendGetLogConfirmation(char *uuid)
  7720. {
  7721. mtrace();
  7722. int result = PASS;
  7723. char message[4096]={0};
  7724. json_object *GetLog = json_object_new_object();
  7725. DEBUG_INFO("sendGetLogConfirmation...\n");
  7726. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7727. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7728. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7729. sprintf(message,"[%d,\"%s\",%s]"
  7730. ,MESSAGE_TYPE_CALLRESULT
  7731. ,uuid
  7732. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7733. json_object_put(GetLog);
  7734. LWS_Send(message);
  7735. return result;
  7736. }
  7737. int sendInstallCertificateConfirmation(char *uuid)
  7738. {
  7739. mtrace();
  7740. int result = PASS;
  7741. char message[4096]={0};
  7742. json_object *InstallCertificate = json_object_new_object();
  7743. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7744. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7745. sprintf(message,"[%d,\"%s\",%s]"
  7746. ,MESSAGE_TYPE_CALLRESULT
  7747. ,uuid
  7748. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7749. json_object_put(InstallCertificate);
  7750. LWS_Send(message);
  7751. return result;
  7752. }
  7753. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7754. {
  7755. mtrace();
  7756. int result = PASS;
  7757. char message[4096]={0};
  7758. json_object *SignedUpdateFirmware = json_object_new_object();
  7759. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7760. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7761. sprintf(message,"[%d,\"%s\",%s]"
  7762. ,MESSAGE_TYPE_CALLRESULT
  7763. ,uuid
  7764. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7765. json_object_put(SignedUpdateFirmware);
  7766. LWS_Send(message);
  7767. return result;
  7768. }
  7769. int sendUnknownConfirmation(char *uuid)
  7770. {
  7771. mtrace();
  7772. int result = PASS;
  7773. char message[256]={0};
  7774. DEBUG_INFO("sendUnknownConfirmation...\n");
  7775. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7776. LWS_Send(message);
  7777. return result;
  7778. }
  7779. //==========================================
  7780. // Handle server request routine Start
  7781. //==========================================
  7782. int handleCancelReservationRequest(char *uuid, char *payload)
  7783. {
  7784. mtrace();
  7785. int result = FAIL;
  7786. int gunNO = 0;
  7787. int reservationIdInt = -1;
  7788. char comfirmstr[20];
  7789. DEBUG_INFO("handleCancelReservationRequest...\n");
  7790. json_object *CancelReservation;
  7791. CancelReservation = json_tokener_parse(payload);
  7792. if(!is_error(CancelReservation))
  7793. {
  7794. // Required data
  7795. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7796. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7797. }
  7798. json_object_put(CancelReservation);
  7799. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7800. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7801. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7802. if(reservationIdInt != -1)
  7803. {
  7804. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7805. //check Transaction active
  7806. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7808. {
  7809. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7810. {
  7811. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7812. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7813. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7814. {
  7815. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7816. }
  7817. else
  7818. {
  7819. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7820. }
  7821. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7822. goto end;
  7823. }
  7824. }
  7825. for (int index = 0; index < CCS_QUANTITY; index++)
  7826. {
  7827. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7828. {
  7829. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7830. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7831. if(gunType[2] == GUN_TYPE_CCS)
  7832. {
  7833. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7834. }
  7835. else
  7836. {
  7837. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7838. }
  7839. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7840. goto end;
  7841. }
  7842. }
  7843. for (int index = 0; index < GB_QUANTITY; index++)
  7844. {
  7845. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7846. {
  7847. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7848. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7849. if(gunType[2] == GUN_TYPE_GBT)
  7850. {
  7851. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7852. }
  7853. else
  7854. {
  7855. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7856. }
  7857. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7858. goto end;
  7859. }
  7860. }
  7861. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7862. {
  7863. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7864. {
  7865. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7866. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7867. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7868. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7869. goto end;
  7870. }
  7871. }
  7872. for (int index = 0; index < AC_QUANTITY; index++)
  7873. {
  7874. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7875. {
  7876. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7877. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7879. {
  7880. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7881. }
  7882. else
  7883. {
  7884. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7885. }
  7886. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7887. goto end;
  7888. }
  7889. }
  7890. }
  7891. //The reservationId does NOT match the reservationId
  7892. sendCancelReservationConfirmation(uuid, comfirmstr);
  7893. end:
  7894. // Fill in ocpp packet uuid
  7895. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7896. return result;
  7897. }
  7898. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7899. {
  7900. mtrace();
  7901. int result = FAIL;
  7902. int gunIndex = -1;
  7903. char typeStr[16]={0};
  7904. char comfirmstr[20];
  7905. int specificId = FALSE;
  7906. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7907. json_object *ChangeAvailability;
  7908. ChangeAvailability = json_tokener_parse(payload);
  7909. if(!is_error(ChangeAvailability))
  7910. {
  7911. // Required data
  7912. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7913. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7914. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7915. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7916. }
  7917. json_object_put(ChangeAvailability);
  7918. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7919. {
  7920. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7921. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7922. }
  7923. else if(gunIndex == 0)
  7924. {
  7925. for(int i=0; i < gunTotalNumber; i++)
  7926. {
  7927. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7928. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7929. }
  7930. }
  7931. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7932. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7933. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7934. {
  7935. specificId = TRUE;
  7936. }
  7937. if(specificId == FALSE)
  7938. goto end;
  7939. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7940. {
  7941. //----------------------gunIndex is 0 ------------------------------------------------//
  7942. if(gunIndex == 0)
  7943. {
  7944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7945. {
  7946. for(int i=0; i < gunTotalNumber; i++)
  7947. {
  7948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7949. {
  7950. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7951. {
  7952. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7953. {
  7954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7955. goto end;
  7956. }
  7957. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7958. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7959. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7960. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7961. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7962. {
  7963. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7964. goto end;
  7965. }
  7966. }
  7967. }//END FOR CHAdeMO_QUANTITY
  7968. for (int index = 0; index < CCS_QUANTITY; index++)
  7969. {
  7970. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7971. {
  7972. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7973. {
  7974. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7975. goto end;
  7976. }
  7977. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7978. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7979. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7980. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7981. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7982. {
  7983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7984. goto end;
  7985. }
  7986. }
  7987. }//END FOR CCS_QUANTITY
  7988. for (int index = 0; index < GB_QUANTITY; index++)
  7989. {
  7990. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7991. {
  7992. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7993. {
  7994. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7995. goto end;
  7996. }
  7997. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7998. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7999. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8000. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8001. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8002. {
  8003. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8004. goto end;
  8005. }
  8006. }
  8007. }// END FOR GB_QUANTITY
  8008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8009. {
  8010. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8011. {
  8012. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8013. {
  8014. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8015. goto end;
  8016. }
  8017. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8018. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8019. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8020. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8021. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8022. {
  8023. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8024. goto end;
  8025. }
  8026. }
  8027. }// END FOR GENERAL_GUN_QUANTITY
  8028. for (int index = 0; index < AC_QUANTITY; index++)
  8029. {
  8030. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8031. {
  8032. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8033. {
  8034. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8035. goto end;
  8036. }
  8037. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8038. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8039. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8040. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8041. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8042. {
  8043. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8044. goto end;
  8045. }
  8046. }
  8047. }//END FOR AC_QUANTITY
  8048. }// END FOR gunTotalNumber
  8049. }
  8050. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8051. {
  8052. for(int i=0; i < gunTotalNumber; i++)
  8053. {
  8054. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8055. {
  8056. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8057. goto end;
  8058. }
  8059. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8060. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8061. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8062. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8063. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8064. {
  8065. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8066. goto end;
  8067. }
  8068. }
  8069. }
  8070. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8071. goto end;
  8072. }
  8073. //----------------------gunIndex is not 0 ------------------------------------------------//
  8074. //check Transaction active
  8075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8076. {
  8077. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8078. {
  8079. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8080. {
  8081. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8082. goto end;
  8083. }
  8084. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8087. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8088. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8089. {
  8090. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8091. goto end;
  8092. }
  8093. else
  8094. {
  8095. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8096. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8097. goto end;
  8098. }
  8099. }
  8100. }//END FOR CHAdeMO_QUANTITY
  8101. for (int index = 0; index < CCS_QUANTITY; index++)
  8102. {
  8103. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8104. {
  8105. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8106. {
  8107. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8108. goto end;
  8109. }
  8110. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8115. {
  8116. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8117. goto end;
  8118. }
  8119. else
  8120. {
  8121. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8123. goto end;
  8124. }
  8125. }
  8126. }//END FOR CCS_QUANTITY
  8127. for (int index = 0; index < GB_QUANTITY; index++)
  8128. {
  8129. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8130. {
  8131. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8132. {
  8133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8134. goto end;
  8135. }
  8136. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8141. {
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8143. goto end;
  8144. }
  8145. else
  8146. {
  8147. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8148. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8149. goto end;
  8150. }
  8151. }
  8152. }// END FOR GB_QUANTITY
  8153. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8154. {
  8155. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8156. {
  8157. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8158. {
  8159. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8160. goto end;
  8161. }
  8162. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8163. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8167. {
  8168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8169. goto end;
  8170. }
  8171. else
  8172. {
  8173. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8174. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8175. goto end;
  8176. }
  8177. }
  8178. }// END FOR GENERAL_GUN_QUANTITY
  8179. for (int index = 0; index < AC_QUANTITY; index++)
  8180. {
  8181. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8182. {
  8183. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8184. {
  8185. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8186. goto end;
  8187. }
  8188. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8191. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8193. {
  8194. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8195. goto end;
  8196. }
  8197. else
  8198. {
  8199. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8201. goto end;
  8202. }
  8203. }
  8204. }//END FOR AC_QUANTITY
  8205. }//END FOR AvailabilityTypeStr[Inoperative]
  8206. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8207. {
  8208. //----------------------gunIndex is 0 ------------------------------------------------//
  8209. if(gunIndex == 0)
  8210. {
  8211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8212. {
  8213. for(int i=0; i < gunTotalNumber; i++)
  8214. {
  8215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8216. {
  8217. 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
  8218. {
  8219. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8220. goto end;
  8221. }
  8222. }//END FOR CHAdeMO_QUANTITY
  8223. for (int index = 0; index < CCS_QUANTITY; index++)
  8224. {
  8225. 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
  8226. {
  8227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8228. goto end;
  8229. }
  8230. }//END FOR CCS_QUANTITY
  8231. for (int index = 0; index < GB_QUANTITY; index++)
  8232. {
  8233. 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
  8234. {
  8235. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8236. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8237. goto end;
  8238. }
  8239. }// END FOR GB_QUANTITY
  8240. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8241. {
  8242. 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
  8243. {
  8244. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8245. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8246. goto end;
  8247. }
  8248. }// END FOR GENERAL_GUN_QUANTITY
  8249. for (int index = 0; index < AC_QUANTITY; index++)
  8250. {
  8251. 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
  8252. {
  8253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8254. goto end;
  8255. }
  8256. }//END FOR CHAdeMO_QUANTITY
  8257. }// END FOR gunTotalNumber
  8258. }
  8259. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8260. {
  8261. for(int i=0; i < gunTotalNumber; i++)
  8262. {
  8263. for (int index = 0; index < AC_QUANTITY; index++)
  8264. {
  8265. 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
  8266. {
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8268. goto end;
  8269. }
  8270. }//END FOR CHAdeMO_QUANTITY
  8271. } // END FOR gunTotalNumber
  8272. }
  8273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8274. goto end;
  8275. }
  8276. //----------------------gunIndex is not 0 ------------------------------------------------//
  8277. //check Transaction active
  8278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8279. {
  8280. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8281. {
  8282. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8283. goto end;
  8284. }
  8285. }//END FOR CHAdeMO_QUANTITY
  8286. for (int index = 0; index < CCS_QUANTITY; index++)
  8287. {
  8288. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8289. {
  8290. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8291. goto end;
  8292. }
  8293. }//END FOR CCS_QUANTITY
  8294. for (int index = 0; index < GB_QUANTITY; index++)
  8295. {
  8296. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8297. {
  8298. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8299. goto end;
  8300. }
  8301. }// END FOR GB_QUANTITY
  8302. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8303. {
  8304. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8305. {
  8306. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8307. goto end;
  8308. }
  8309. }// END FOR GENERAL_GUN_QUANTITY
  8310. for (int index = 0; index < AC_QUANTITY; index++)
  8311. {
  8312. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8313. {
  8314. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8315. goto end;
  8316. }
  8317. }//END FOR AC_QUANTITY
  8318. }//END FOR AvailabilityTypeStr[Operative]
  8319. end:
  8320. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8321. {
  8322. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8323. }
  8324. else
  8325. {
  8326. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8327. }
  8328. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8329. {
  8330. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8331. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8332. }
  8333. else if(gunIndex == 0)
  8334. {
  8335. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8336. {
  8337. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8338. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8339. }
  8340. }
  8341. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8342. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8343. return result;
  8344. }
  8345. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8346. {
  8347. mtrace();
  8348. int valueInvalid = NO;
  8349. int result = FAIL;
  8350. char keystr[40]={0};
  8351. char valuestr[501]={0}; //value should be limited in 500 bytes
  8352. char comfirmstr[20]={0};
  8353. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8354. json_object *ChangeConfiguration;
  8355. ChangeConfiguration = json_tokener_parse(payload);
  8356. if(!is_error(ChangeConfiguration))
  8357. {
  8358. // Required data
  8359. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8360. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8361. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8362. {
  8363. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8364. }
  8365. else
  8366. {
  8367. valueInvalid = YES;
  8368. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8369. }
  8370. }
  8371. json_object_put(ChangeConfiguration);
  8372. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8373. {
  8374. DEBUG_ERROR("Payload is null or not accepted.\n");
  8375. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8376. }
  8377. else
  8378. {
  8379. int status = setKeyValue(keystr, valuestr);
  8380. switch(status)
  8381. {
  8382. case ConfigurationStatus_Accepted:
  8383. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8384. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8385. StoreConfigurationTable();
  8386. break;
  8387. case RebootRequired:
  8388. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8389. StoreConfigurationTable();
  8390. break;
  8391. case NotSupported:
  8392. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8393. break;
  8394. case ConfigurationStatus_Rejected:
  8395. default:
  8396. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8397. break;
  8398. }
  8399. }
  8400. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8401. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8402. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8403. {
  8404. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8405. SetOcppConnStatus(FALSE);
  8406. }
  8407. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8408. {
  8409. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8410. }
  8411. return result;
  8412. }
  8413. int handleClearCacheRequest(char *uuid, char *payload)
  8414. {
  8415. mtrace();
  8416. int result = FAIL;
  8417. char comfirmstr[20];
  8418. char rmFileCmd[100]={0};
  8419. struct stat stats;
  8420. DEBUG_INFO("handleClearCacheRequest...\n");
  8421. stat("/Storage/OCPP_PH", &stats);
  8422. // Check for directory existence
  8423. if (S_ISDIR(stats.st_mode) == 1)
  8424. {}
  8425. else
  8426. {
  8427. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8428. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8429. system(rmFileCmd);
  8430. }
  8431. if(OCPP_cleanLocalCache())
  8432. {
  8433. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8434. }
  8435. else
  8436. {
  8437. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8438. }
  8439. sendClearCacheConfirmation(uuid, comfirmstr);
  8440. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8441. return result;
  8442. }
  8443. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8444. {
  8445. mtrace();
  8446. int result = FAIL;
  8447. int resultRename;
  8448. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8449. char chargingProfilePurposeStr[26]={0};
  8450. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8451. char tempchargingProfilePurposeStr[26]={0};
  8452. char str[100]={0};
  8453. char fname[200]={0};
  8454. char comfirmstr[20]={0};
  8455. char word[1600]={0};
  8456. int clearflag = FALSE;
  8457. int chargingProfileIdIsNULL = FALSE;
  8458. int connectorIsNULL = FALSE;
  8459. int chargingProfilePurposeIsNULL = FALSE;
  8460. int stackLevelIsNULL = FALSE;
  8461. //int GotoEnd = FALSE;
  8462. FILE *fptr1, *fptr2;
  8463. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8464. int n_chargingProfile=0;
  8465. int isEmptyFile = FALSE;
  8466. char sLineWord[1600]={0};
  8467. char chargingProfiles[10][100]={0};
  8468. int ChargeProfileCount = 0;
  8469. int ch;
  8470. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8471. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8472. json_object *ClearChargingProfile;
  8473. ClearChargingProfile = json_tokener_parse(payload);
  8474. if(!is_error(ClearChargingProfile))
  8475. {
  8476. // Optional data
  8477. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8478. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8479. else
  8480. chargingProfileIdIsNULL = TRUE;
  8481. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8482. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8483. else
  8484. connectorIsNULL = TRUE;
  8485. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8486. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8487. else
  8488. chargingProfilePurposeIsNULL = TRUE;
  8489. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8490. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8491. else
  8492. stackLevelIsNULL = TRUE;
  8493. }
  8494. json_object_put(ClearChargingProfile);
  8495. if(connectorIsNULL == FALSE)
  8496. {
  8497. switch(connectorIdInt)
  8498. {
  8499. case 0:
  8500. if(chargingProfilePurposeIsNULL == TRUE)
  8501. {
  8502. int l = 0;
  8503. strcpy(fname, ChargePointMaxProfile_JSON);
  8504. if((access(fname,F_OK))!=-1)
  8505. {
  8506. strcpy(chargingProfiles[l], fname);
  8507. l = l + 1;
  8508. }
  8509. strcpy(fname, TxDefaultProfile_0_JSON);
  8510. if((access(fname,F_OK))!=-1)
  8511. {
  8512. strcpy(chargingProfiles[l], fname);
  8513. l = l + 1;
  8514. }
  8515. ChargeProfileCount = l;
  8516. }
  8517. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8518. {
  8519. strcpy(fname, ChargePointMaxProfile_JSON);
  8520. if((access(fname,F_OK))!=-1)
  8521. {
  8522. strcpy(chargingProfiles[0], fname);
  8523. ChargeProfileCount = 1;
  8524. }
  8525. }
  8526. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8527. {
  8528. strcpy(fname, TxDefaultProfile_0_JSON);
  8529. if((access(fname,F_OK))!=-1)
  8530. {
  8531. strcpy(chargingProfiles[0], fname);
  8532. ChargeProfileCount = 1;
  8533. }
  8534. }
  8535. break;
  8536. default:
  8537. if(chargingProfilePurposeIsNULL == TRUE)
  8538. {
  8539. int m = 0;
  8540. memset(fname, 0, ARRAY_SIZE(fname));
  8541. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8542. if((access(fname,F_OK))!=-1)
  8543. {
  8544. strcpy(chargingProfiles[m], fname);
  8545. m = m + 1;
  8546. }
  8547. memset(fname, 0, ARRAY_SIZE(fname));
  8548. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8549. if((access(fname,F_OK))!=-1)
  8550. {
  8551. strcpy(chargingProfiles[m], fname);
  8552. m = m + 1;
  8553. }
  8554. ChargeProfileCount = m;
  8555. }
  8556. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8557. {
  8558. //strcpy(fname, TxDefaultProfile_1_JSON);
  8559. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8560. if((access(fname,F_OK))!=-1)
  8561. {
  8562. strcpy(chargingProfiles[0], fname);
  8563. ChargeProfileCount = 1;
  8564. }
  8565. }
  8566. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8567. {
  8568. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8569. if((access(fname,F_OK))!=-1)
  8570. {
  8571. strcpy(chargingProfiles[0], fname);
  8572. ChargeProfileCount = 1;
  8573. }
  8574. //strcpy(fname, TxProfile_1_JSON);
  8575. }
  8576. //strcpy(fname, ChargePointMaxProfile_JSON );
  8577. break;
  8578. }
  8579. }
  8580. else // Check all Charging Profiles
  8581. {
  8582. int i = 0;
  8583. char fnametemp[200]={0};
  8584. ChargeProfileCount = 0;
  8585. //Check ChargePointMaxProfile.json exit
  8586. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8587. {
  8588. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8589. i = i + 1;
  8590. }
  8591. //Check TxDefaultProfile_0.json exit
  8592. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8593. {
  8594. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8595. i = i + 1;
  8596. }
  8597. //Check TxDefaultProfile_%d.json
  8598. for(int j=1; j <= gunTotalNumber; j++)
  8599. {
  8600. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8601. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8602. if((access(fnametemp,F_OK))!=-1)
  8603. {
  8604. strcpy(chargingProfiles[i], fnametemp);
  8605. i = i + 1;
  8606. }
  8607. }
  8608. //Check TxProfile_%d.json
  8609. for(int j=1; j <= gunTotalNumber; j++)
  8610. {
  8611. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8612. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8613. if((access(fnametemp,F_OK))!=-1)
  8614. {
  8615. strcpy(chargingProfiles[i], fnametemp);
  8616. i = i + 1;
  8617. }
  8618. }
  8619. ChargeProfileCount = i;
  8620. }// End connectorIsNULL is TRUE
  8621. if(ChargeProfileCount == 0)
  8622. {
  8623. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8624. goto end;
  8625. }
  8626. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8627. {
  8628. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8629. goto end;
  8630. }
  8631. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8632. {
  8633. memset(str, 0, ARRAY_SIZE(str));
  8634. // clear temp file
  8635. sprintf(str,"rm -f %s",temp);
  8636. system(str);
  8637. for(int k=0; k < ChargeProfileCount; k++)
  8638. {
  8639. memset(str, 0, ARRAY_SIZE(str));
  8640. //clear file in C
  8641. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8642. system(str);
  8643. }
  8644. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8645. goto end;
  8646. }
  8647. else if(connectorIsNULL == TRUE)
  8648. {
  8649. for(int k=0; k < ChargeProfileCount; k++)
  8650. {
  8651. fptr1 = fopen(chargingProfiles[k], "r");
  8652. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8653. //Check Charging Profile Count
  8654. while(fscanf(fptr1, "%s", word) != EOF)
  8655. {
  8656. //DEBUG_INFO("word=%s\n",word);
  8657. if(strstr(word, "chargingProfileId")!= NULL)
  8658. {
  8659. //DEBUG_INFO("test chargingProfileId \n");
  8660. n_chargingProfile = n_chargingProfile + 1;
  8661. //DEBUG_INFO("chargingProfileId Found\n");
  8662. }
  8663. }
  8664. rewind(fptr1);
  8665. //search Charging Profile Element
  8666. //int i= 0;
  8667. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8668. {
  8669. json_object *tmpProfilee;
  8670. tmpProfilee = json_tokener_parse(sLineWord);
  8671. if(!is_error(tmpProfilee))
  8672. {
  8673. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8674. {
  8675. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8676. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8677. }
  8678. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8679. {
  8680. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8681. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8682. }
  8683. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8684. {
  8685. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8686. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8687. }
  8688. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8689. {
  8690. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8691. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8692. }
  8693. }
  8694. json_object_put(tmpProfilee);
  8695. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8696. {
  8697. //------- not write to fptr2-------//
  8698. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8699. //clearflag = TRUE;
  8700. }
  8701. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8702. {
  8703. //------- not write to fptr2-------//
  8704. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8705. }
  8706. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8707. {
  8708. //------- not write to fptr2-------//
  8709. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8710. }
  8711. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8712. {
  8713. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8714. }
  8715. else
  8716. {
  8717. fprintf(fptr2, sLineWord);//writing data into file
  8718. }
  8719. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8720. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8721. if(clearflag == TRUE)
  8722. {
  8723. fclose(fptr1);
  8724. fclose(fptr2);
  8725. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8726. system(str);
  8727. // clear temp file
  8728. sprintf(str,"rm -f %s",temp);
  8729. system(str);
  8730. }
  8731. else
  8732. {
  8733. fclose(fptr1);
  8734. fclose(fptr2);
  8735. memset(str, 0, ARRAY_SIZE(str));
  8736. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8737. system(str);
  8738. resultRename = rename(temp, chargingProfiles[k]);
  8739. if(resultRename == 0)
  8740. {
  8741. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8742. }
  8743. else
  8744. {
  8745. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8746. }
  8747. if(comfirmstr[0]== 0)
  8748. {
  8749. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8750. }
  8751. //Check chargingProfile is empty file
  8752. /*------ Read the file ----------------*/
  8753. fptr1=fopen(chargingProfiles[k],"r");
  8754. ch=fgetc(fptr1);
  8755. rewind(fptr1);
  8756. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8757. if(ch!=EOF)
  8758. {
  8759. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8760. {
  8761. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8762. if(sLineWord[0]=='\0')
  8763. {
  8764. isEmptyFile = TRUE;
  8765. break;
  8766. }
  8767. else
  8768. {
  8769. isEmptyFile = FALSE;
  8770. break;
  8771. }
  8772. }
  8773. }
  8774. else
  8775. isEmptyFile = TRUE;
  8776. fclose(fptr1);
  8777. if(isEmptyFile == TRUE)
  8778. {
  8779. memset(str, 0, ARRAY_SIZE(str));
  8780. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8781. system(str);
  8782. }
  8783. }
  8784. }// End of while(int k=0; k < ChargePointCount; k++)
  8785. }
  8786. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8787. {
  8788. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8789. for(int k=0; k < ChargeProfileCount; k++)
  8790. {
  8791. fptr1 = fopen(chargingProfiles[k], "r");
  8792. fptr2 = fopen(temp, "w+");
  8793. //Check Charging Profile Count
  8794. while(fscanf(fptr1, "%s", word) != EOF)
  8795. {
  8796. //DEBUG_INFO("word=%s\n",word);
  8797. if(strstr(word, "chargingProfileId")!= NULL)
  8798. {
  8799. n_chargingProfile = n_chargingProfile + 1;
  8800. }
  8801. }
  8802. rewind(fptr1);
  8803. //search Charging Profile Element
  8804. //int i= 0;
  8805. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8806. {
  8807. json_object *tmpProfilee;
  8808. tmpProfilee = json_tokener_parse(sLineWord);
  8809. if(!is_error(tmpProfilee))
  8810. {
  8811. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8812. {
  8813. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8814. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8815. }
  8816. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8817. {
  8818. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8819. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8820. }
  8821. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8822. {
  8823. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8824. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8825. }
  8826. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8827. {
  8828. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8829. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8830. }
  8831. }
  8832. json_object_put(tmpProfilee);
  8833. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8834. {
  8835. //------- not write to fptr2-------//
  8836. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8837. //clearflag = TRUE;
  8838. }
  8839. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8840. {
  8841. //------- not write to fptr2-------//
  8842. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8843. }
  8844. else if(stackLevelIsNULL == TRUE)
  8845. {
  8846. //Clear Whole File
  8847. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8848. clearflag = TRUE;
  8849. break;
  8850. }
  8851. else
  8852. {
  8853. fprintf(fptr2, sLineWord);//writing data into file
  8854. }
  8855. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8856. }
  8857. if(clearflag == TRUE)
  8858. {
  8859. fclose(fptr1);
  8860. fclose(fptr2);
  8861. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8862. system(str);
  8863. // clear temp file
  8864. sprintf(str,"rm -f %s",temp);
  8865. system(str);
  8866. }
  8867. else
  8868. {
  8869. fclose(fptr1);
  8870. fclose(fptr2);
  8871. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8872. system(str);
  8873. resultRename = rename(temp, chargingProfiles[k]);
  8874. if(resultRename == 0)
  8875. {
  8876. DEBUG_INFO("File ChargingProfile renamed successfully");
  8877. }
  8878. else
  8879. {
  8880. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8881. }
  8882. if(comfirmstr[0]== 0)
  8883. {
  8884. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8885. }
  8886. //Check chargingProfile is empty file
  8887. /*------ Read the file ----------------*/
  8888. fptr1=fopen(chargingProfiles[k],"r");
  8889. ch=fgetc(fptr1);
  8890. rewind(fptr1);
  8891. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8892. if(ch!=EOF)
  8893. {
  8894. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8895. {
  8896. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8897. if(sLineWord[0]=='\0')
  8898. {
  8899. isEmptyFile = TRUE;
  8900. break;
  8901. }
  8902. else
  8903. {
  8904. isEmptyFile = FALSE;
  8905. break;
  8906. }
  8907. }
  8908. }
  8909. else
  8910. isEmptyFile = TRUE;
  8911. fclose(fptr1);
  8912. if(isEmptyFile == TRUE)
  8913. {
  8914. memset(str, 0, ARRAY_SIZE(str));
  8915. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8916. system(str);
  8917. }
  8918. /*------- End of reading ---------------*/
  8919. }
  8920. } // while(int k=0; k < ChargeProfileCount; k++)
  8921. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8922. end:
  8923. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8924. {
  8925. if(connectorIdInt == 0)
  8926. {
  8927. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8928. {
  8929. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8930. }
  8931. }
  8932. else
  8933. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8934. }
  8935. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8936. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8937. return result;
  8938. }
  8939. void createFirmwareVersionByDataTransfer(void)
  8940. {
  8941. json_object *FirmwareDataTransfer = json_object_new_object();
  8942. // AC & DC model
  8943. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8944. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8945. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8946. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8947. // DC model
  8948. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8949. {
  8950. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8951. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8952. (gunType[3] != GUN_TYPE_UNKNOWN))
  8953. {
  8954. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8955. }
  8956. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8957. {
  8958. // DS DM DW
  8959. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8960. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8961. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8962. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8964. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8965. }
  8966. else
  8967. {
  8968. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8969. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8970. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8971. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8979. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8980. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8981. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8982. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8983. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8984. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8985. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8986. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8987. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8988. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8989. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8990. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8991. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8992. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8993. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8994. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8995. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8996. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8997. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8998. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8999. }
  9000. }
  9001. // 4G model
  9002. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9003. {
  9004. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9005. }
  9006. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9007. json_object_put(FirmwareDataTransfer);
  9008. }
  9009. int handleDataTransferRequest(char *uuid, char *payload)
  9010. {
  9011. mtrace();
  9012. json_object *response = json_object_new_object();
  9013. int result = FAIL;
  9014. char tempvendorId[255]={0};
  9015. char tempmessageId[50]={0};
  9016. char tempdata[512]={0};
  9017. char message[2048]={0};
  9018. DEBUG_INFO("handleDataTransferRequest...\n");
  9019. if((uuid != NULL) && (payload != NULL))
  9020. {
  9021. json_object *DataTransfer;
  9022. DataTransfer = json_tokener_parse(payload);
  9023. if(!is_error(DataTransfer))
  9024. {
  9025. // Required data
  9026. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9027. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9028. // Optional data
  9029. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9030. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9031. if(json_object_object_get(DataTransfer, "data") != NULL)
  9032. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9033. result = PASS;
  9034. }
  9035. json_object_put(DataTransfer);
  9036. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9037. {
  9038. // Send all moudle firmware version on EVSE
  9039. createFirmwareVersionByDataTransfer();
  9040. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9041. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9042. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9043. json_object_put(response);
  9044. }
  9045. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9046. {
  9047. system("/usr/bin/run_tmate_restart.sh &");
  9048. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9049. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9050. json_object_put(response);
  9051. }
  9052. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9053. {
  9054. json_object *data;
  9055. data = json_tokener_parse(tempdata);
  9056. if(!is_error(data))
  9057. {
  9058. 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))
  9059. {
  9060. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9061. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9062. if(json_object_object_get(data, "SOC") != NULL)
  9063. {
  9064. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9065. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9066. }
  9067. if(json_object_object_get(data, "Energy") != NULL)
  9068. {
  9069. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9070. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9071. }
  9072. if(json_object_object_get(data, "Duration") != NULL)
  9073. {
  9074. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9075. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9076. }
  9077. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9078. }
  9079. else
  9080. {
  9081. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9082. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9083. }
  9084. }
  9085. else
  9086. {
  9087. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9088. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9089. }
  9090. json_object_put(data);
  9091. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9092. json_object_put(response);
  9093. }
  9094. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9095. {
  9096. json_object *data;
  9097. data = json_tokener_parse(tempdata);
  9098. if(!is_error(data))
  9099. {
  9100. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9101. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9102. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9103. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9104. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9105. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9106. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9107. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9108. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9109. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9110. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9111. }
  9112. else
  9113. {
  9114. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9115. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9116. }
  9117. json_object_put(data);
  9118. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9119. json_object_put(response);
  9120. }
  9121. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9122. {
  9123. json_object *data;
  9124. data = json_tokener_parse(tempdata);
  9125. if(!is_error(data))
  9126. {
  9127. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9128. if(json_object_object_get(data, "idToken") != NULL)
  9129. {
  9130. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9131. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9132. }
  9133. if(json_object_object_get(data, "price") != NULL)
  9134. {
  9135. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9136. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9137. }
  9138. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9139. }
  9140. else
  9141. {
  9142. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9143. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9144. }
  9145. json_object_put(data);
  9146. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9147. json_object_put(response);
  9148. }
  9149. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9150. {
  9151. json_object *data;
  9152. data = json_tokener_parse(tempdata);
  9153. if(!is_error(data))
  9154. {
  9155. if(json_object_object_get(data, "txId") != NULL)
  9156. {
  9157. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9158. for(int idx = 0;idx<gunTotalNumber;idx++)
  9159. {
  9160. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9161. {
  9162. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9163. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9164. if(json_object_object_get(data, "description") != NULL)
  9165. {
  9166. // California pricing V1.0
  9167. DEBUG_INFO("California pricing V1.0\n");
  9168. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9169. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9170. }
  9171. else
  9172. {
  9173. // California pricing V1.1
  9174. DEBUG_INFO("California pricing V1.1\n");
  9175. if(json_object_object_get(data, "timestamp") != NULL)
  9176. {
  9177. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9178. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9179. }
  9180. if(json_object_object_get(data, "meterValue") != NULL)
  9181. {
  9182. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9183. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9184. }
  9185. if(json_object_object_get(data, "cost") != NULL)
  9186. {
  9187. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9188. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9189. }
  9190. if(json_object_object_get(data, "state") != NULL)
  9191. {
  9192. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9193. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9194. }
  9195. if(json_object_object_get(data, "chargingPrice") != NULL)
  9196. {
  9197. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9198. {
  9199. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9200. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9201. }
  9202. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9203. {
  9204. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9205. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9206. }
  9207. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9208. {
  9209. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9210. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9211. }
  9212. }
  9213. if(json_object_object_get(data, "idlePrice") != NULL)
  9214. {
  9215. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9216. {
  9217. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9218. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9219. }
  9220. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9221. {
  9222. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9223. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9224. }
  9225. }
  9226. if(json_object_object_get(data, "nextPeriod") != NULL)
  9227. {
  9228. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9229. {
  9230. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9231. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9232. }
  9233. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9234. {
  9235. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9236. {
  9237. 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")));
  9238. 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"));
  9239. }
  9240. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9241. {
  9242. 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")));
  9243. 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"));
  9244. }
  9245. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9246. {
  9247. 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")));
  9248. 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"));
  9249. }
  9250. }
  9251. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9252. {
  9253. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9254. {
  9255. 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")));
  9256. 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"));
  9257. }
  9258. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9259. {
  9260. 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")));
  9261. 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"));
  9262. }
  9263. }
  9264. }
  9265. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9266. {
  9267. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9268. {
  9269. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9270. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9271. }
  9272. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9273. {
  9274. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9275. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9276. }
  9277. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9278. {
  9279. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9280. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9281. }
  9282. }
  9283. }
  9284. }
  9285. }
  9286. }
  9287. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9288. }
  9289. else
  9290. {
  9291. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9292. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9293. }
  9294. json_object_put(data);
  9295. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9296. json_object_put(response);
  9297. }
  9298. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9299. {
  9300. json_object *data;
  9301. data = json_tokener_parse(tempdata);
  9302. if(!is_error(data))
  9303. {
  9304. if(json_object_object_get(data, "txId") != NULL)
  9305. {
  9306. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9307. for(int idx = 0;idx<gunTotalNumber;idx++)
  9308. {
  9309. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9310. {
  9311. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9312. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9313. if(json_object_object_get(data, "description") != NULL)
  9314. {
  9315. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9316. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9317. }
  9318. }
  9319. }
  9320. }
  9321. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9322. }
  9323. else
  9324. {
  9325. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9326. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9327. }
  9328. json_object_put(data);
  9329. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9330. json_object_put(response);
  9331. }
  9332. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9333. {
  9334. json_object *data;
  9335. data = json_tokener_parse(tempdata);
  9336. if(!is_error(data))
  9337. {
  9338. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9339. if(json_object_object_get(data, "Content_Type") != NULL)
  9340. {
  9341. 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))
  9342. {
  9343. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9344. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9345. {
  9346. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9347. }
  9348. }
  9349. else
  9350. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9351. }
  9352. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9353. }
  9354. else
  9355. {
  9356. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9357. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9358. }
  9359. json_object_put(data);
  9360. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9361. json_object_put(response);
  9362. }
  9363. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9364. {
  9365. json_object *data;
  9366. data = json_tokener_parse(tempdata);
  9367. if(!is_error(data))
  9368. {
  9369. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9370. if(json_object_object_get(data, "ConnectorId") != NULL)
  9371. {
  9372. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9373. }
  9374. if(json_object_object_get(data, "SerialNo") != NULL)
  9375. {
  9376. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9377. }
  9378. if(json_object_object_get(data, "Page_Index") != NULL)
  9379. {
  9380. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9381. }
  9382. if(json_object_object_get(data, "Duration") != NULL)
  9383. {
  9384. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9385. }
  9386. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9387. }
  9388. else
  9389. {
  9390. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9391. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9392. }
  9393. json_object_put(data);
  9394. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9395. json_object_put(response);
  9396. }
  9397. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9398. {
  9399. json_object *data;
  9400. data = json_tokener_parse(tempdata);
  9401. if(!is_error(data))
  9402. {
  9403. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9404. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9405. {
  9406. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9407. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9408. else
  9409. {
  9410. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9411. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9412. }
  9413. }
  9414. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9415. {
  9416. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9417. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9418. else
  9419. {
  9420. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9421. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9422. }
  9423. }
  9424. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9425. {
  9426. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9427. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9428. else
  9429. {
  9430. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9431. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9432. }
  9433. }
  9434. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9435. {
  9436. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9437. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9438. else
  9439. {
  9440. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9441. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9442. }
  9443. }
  9444. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9445. {
  9446. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9447. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  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. }
  9454. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9455. {
  9456. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9457. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9458. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9459. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9460. else
  9461. {
  9462. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9463. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9464. }
  9465. }
  9466. if(json_object_object_get(data, "isAuthentication") != NULL)
  9467. {
  9468. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9469. {
  9470. case 0:
  9471. case 1:
  9472. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9473. break;
  9474. default:
  9475. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9476. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9477. break;
  9478. }
  9479. }
  9480. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9481. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9482. }
  9483. else
  9484. {
  9485. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9486. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9487. }
  9488. json_object_put(data);
  9489. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9490. json_object_put(response);
  9491. }
  9492. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9493. {
  9494. json_object *data;
  9495. data = json_tokener_parse(tempdata);
  9496. if(!is_error(data))
  9497. {
  9498. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9499. if(json_object_object_get(data, "stationName") != NULL)
  9500. {
  9501. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9502. }
  9503. else
  9504. {
  9505. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9506. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9507. }
  9508. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9509. {
  9510. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9511. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9512. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9513. }
  9514. }
  9515. else
  9516. {
  9517. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9518. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9519. }
  9520. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9521. json_object_put(response);
  9522. }
  9523. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9524. {
  9525. json_object *data;
  9526. data = json_tokener_parse(tempdata);
  9527. if(!is_error(data))
  9528. {
  9529. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9530. if(json_object_object_get(data, "weatherId") != NULL)
  9531. {
  9532. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9533. }
  9534. else
  9535. {
  9536. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9537. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9538. }
  9539. if(json_object_object_get(data, "Temperature") != NULL)
  9540. {
  9541. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9542. }
  9543. else
  9544. {
  9545. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9546. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9547. }
  9548. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9549. {
  9550. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9551. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9552. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9553. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9554. }
  9555. }
  9556. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != 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_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9564. {
  9565. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9566. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9567. }
  9568. else
  9569. {
  9570. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9571. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9572. }
  9573. }
  9574. else
  9575. {
  9576. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9577. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9578. }
  9579. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9580. json_object_put(response);
  9581. }
  9582. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9583. {
  9584. json_object *data;
  9585. data = json_tokener_parse(tempdata);
  9586. if(!is_error(data))
  9587. {
  9588. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9589. {
  9590. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9591. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9592. if(gun_index < gunTotalNumber)
  9593. {
  9594. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9595. {
  9596. json_object *responsedata = json_object_new_object();
  9597. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9598. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9599. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9600. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9601. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9602. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9603. }
  9604. else
  9605. {
  9606. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9607. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9608. }
  9609. }
  9610. else
  9611. {
  9612. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9613. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9614. }
  9615. }
  9616. else
  9617. {
  9618. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9619. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9620. }
  9621. }
  9622. else
  9623. {
  9624. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9625. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9626. }
  9627. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9628. json_object_put(response);
  9629. }
  9630. else
  9631. {
  9632. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9633. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9634. }
  9635. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9636. json_object_put(response);
  9637. }
  9638. else
  9639. {
  9640. // Can not find valid message id
  9641. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9642. }
  9643. }
  9644. else
  9645. {
  9646. // Payload is null
  9647. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9648. }
  9649. LWS_Send(message);
  9650. return result;
  9651. }
  9652. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9653. {
  9654. mtrace();
  9655. int result = FAIL;
  9656. int connectorIdInt, durationInt;
  9657. char chargingRateUnitStr[4]={0};
  9658. char comfirmstr[20];
  9659. int confirmPeriods = 0;
  9660. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9661. json_object *GetCompositeSchedule;
  9662. GetCompositeSchedule = json_tokener_parse(payload);
  9663. if(!is_error(GetCompositeSchedule))
  9664. {
  9665. // Required data
  9666. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9667. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9668. else
  9669. connectorIdInt = -1;
  9670. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9671. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9672. else
  9673. durationInt = 86400;
  9674. // Optional data
  9675. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9676. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9677. }
  9678. json_object_put(GetCompositeSchedule);
  9679. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9680. if((connectorIdInt == 0) ||
  9681. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9682. {
  9683. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9684. struct StructChargingProfile tmpProfile[1];
  9685. if(strstr(chargingRateUnitStr, "W") != NULL)
  9686. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9687. else
  9688. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9689. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9690. {
  9691. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9692. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9693. }
  9694. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9695. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9696. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9697. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9698. {
  9699. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9700. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9701. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9702. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9703. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9704. {
  9705. confirmPeriods = idx;
  9706. break;
  9707. }
  9708. }
  9709. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9710. {
  9711. confirmPeriods += 1;
  9712. }
  9713. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9714. }
  9715. else
  9716. {
  9717. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9718. }
  9719. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9720. return result;
  9721. }
  9722. int handleGetConfigurationRequest(char *uuid, char *payload)
  9723. {
  9724. mtrace();
  9725. int result = FAIL;
  9726. int MaxKeySupported = 0;
  9727. int n_keys = 0;
  9728. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9729. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9730. json_object *GetConfiguration;
  9731. GetConfiguration = json_tokener_parse(payload);
  9732. if(!is_error(GetConfiguration))
  9733. {
  9734. // Optional data
  9735. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9736. {
  9737. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9738. {
  9739. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9740. n_keys = idx + 1;
  9741. }
  9742. }
  9743. }
  9744. json_object_put(GetConfiguration);
  9745. UnknownKeynum = 0;
  9746. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9747. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9748. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9749. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9750. if(n_keys != 0)
  9751. {
  9752. for(int i=0;i<n_keys;i++)
  9753. {
  9754. getKeyValue(requestKey[i]);
  9755. }
  9756. }
  9757. else
  9758. {
  9759. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9760. getKeyValue("");
  9761. }
  9762. processUnkownKey();
  9763. sendGetConfigurationConfirmation(uuid);
  9764. return result;
  9765. }
  9766. static char fnamePlusPath[100]={0};
  9767. static char fnamePWithNoPath[60]={0};
  9768. void checkUploadLog(void)
  9769. {
  9770. FILE *fp;
  9771. /* Open the command for reading. */
  9772. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9773. if (fp == NULL) {
  9774. DEBUG_WARN("Failed to run command\n" );
  9775. exit(1);
  9776. }
  9777. int ftppathlen = 0;
  9778. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9779. int i = 0;
  9780. /* Read the output a line at a time - output it. */
  9781. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9782. if(i==0)
  9783. {
  9784. ftppathlen = strlen(fnamePlusPath);
  9785. DEBUG_INFO("%s\n", fnamePlusPath);
  9786. fnamePlusPath[ftppathlen]='\0';
  9787. break;
  9788. }
  9789. i= i+1;
  9790. }
  9791. /* close */
  9792. pclose(fp);
  9793. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9794. {
  9795. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9796. {
  9797. fnamePlusPath[k]='\0';
  9798. }
  9799. }
  9800. i=1;
  9801. //char fname[60]={0};
  9802. while(i < ftppathlen)
  9803. {
  9804. int len=ftppathlen-i;
  9805. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9806. {
  9807. DEBUG_INFO("compare '/' all right\n");
  9808. break;
  9809. }
  9810. i=i+1;
  9811. }
  9812. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9813. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9814. fnamePWithNoPath[i+1] = '\0';
  9815. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9816. {
  9817. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9818. {
  9819. fnamePWithNoPath[j]='\0';
  9820. }
  9821. }
  9822. FILE* fp1 = fopen(fnamePlusPath, "r");
  9823. if (fp1)
  9824. {
  9825. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9826. // file exists
  9827. fclose(fp1);
  9828. }
  9829. else
  9830. {
  9831. // file doesn't exist
  9832. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9833. }
  9834. }
  9835. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9836. {
  9837. mtrace();
  9838. int result = FAIL;
  9839. time_t CurrentTime;
  9840. struct tm *tm;
  9841. pthread_t th_Status;
  9842. CurrentTime = time(NULL);
  9843. tm = localtime(&CurrentTime);
  9844. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9845. 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);
  9846. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9847. if(!interLock.isGetDiagnosticGoing)
  9848. {
  9849. interLock.isGetDiagnosticGoing = 1;
  9850. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9851. sleep(1);
  9852. }
  9853. else
  9854. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9855. return result;
  9856. }
  9857. void* GetDiagnosticsProcess(void* data)
  9858. {
  9859. pthread_detach(pthread_self());
  9860. mtrace();
  9861. int retriesInt=0, retryIntervalInt=0;
  9862. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9863. 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};
  9864. int port=0;
  9865. int isSuccess = FALSE;
  9866. char ftpbuf[200]={0};
  9867. char cmdBuf[2048];
  9868. struct tm *tmNow;
  9869. time_t CurrentTime;
  9870. struct tm tmStart;
  9871. struct tm tmStop;
  9872. CurrentTime = time(NULL);
  9873. tmNow=localtime(&CurrentTime);
  9874. uint16_t targetYear, targetMonth;
  9875. json_object *GetDiagnostics;
  9876. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9877. GetDiagnostics = json_tokener_parse(data);
  9878. if(!is_error(GetDiagnostics))
  9879. {
  9880. // Required data
  9881. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9882. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9883. // Optional data
  9884. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9885. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9886. else
  9887. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9888. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9889. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9890. else
  9891. retryIntervalInt = 30;
  9892. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9893. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9894. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9895. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9896. }
  9897. json_object_put(GetDiagnostics);
  9898. // Pack log to compress file
  9899. 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) &&
  9900. (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))
  9901. {
  9902. // Pack system log
  9903. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9904. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9905. targetYear = tmStart.tm_year;
  9906. targetMonth = tmStart.tm_mon;
  9907. do
  9908. {
  9909. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9910. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9911. if(targetMonth+1>=13)
  9912. {
  9913. targetYear += 1;
  9914. targetMonth = 1;
  9915. }
  9916. else
  9917. {
  9918. targetMonth += 1;
  9919. }
  9920. }while((targetYear < (tmNow->tm_year+1900)) ||
  9921. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9922. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9923. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9924. system(cmdBuf);
  9925. // Pack charging & event log
  9926. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9927. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9928. targetYear = tmStart.tm_year;
  9929. targetMonth = tmStart.tm_mon;
  9930. do
  9931. {
  9932. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9933. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9934. if(targetMonth+1>=13)
  9935. {
  9936. targetYear += 1;
  9937. targetMonth = 1;
  9938. }
  9939. else
  9940. {
  9941. targetMonth += 1;
  9942. }
  9943. }while((targetYear < (tmNow->tm_year+1900)) ||
  9944. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9945. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9946. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9947. system(cmdBuf);
  9948. // Combine log file
  9949. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9950. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9951. }
  9952. else
  9953. {
  9954. system("exec /root/logPackTools 'log' 6");
  9955. }
  9956. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9957. system(cmdBuf);
  9958. checkUploadLog();
  9959. //****************location*******************/
  9960. if(strcmp(locationstr,"")==0)
  9961. {
  9962. DEBUG_INFO("location is <Empty>!\n");
  9963. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9964. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9965. goto end;
  9966. }
  9967. memset(protocol, 0, ARRAY_SIZE(protocol));
  9968. memset(user, 0, ARRAY_SIZE(user) );
  9969. memset(password, 0, ARRAY_SIZE(password));
  9970. memset(host, 0, ARRAY_SIZE(host));
  9971. memset(path, 0, ARRAY_SIZE(path));
  9972. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9973. memset(host1, 0, ARRAY_SIZE(host1));
  9974. memset(path1, 0, ARRAY_SIZE(path1));
  9975. /*location: ftp://user:password@host:port/path*/
  9976. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9977. if((access(fnamePlusPath,F_OK))!=-1)
  9978. {
  9979. DEBUG_INFO("fnamePlusPath exist.\n");
  9980. }
  9981. else
  9982. {
  9983. DEBUG_INFO("fnamePlusPath not exist!\n");
  9984. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9985. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9986. goto end;
  9987. }
  9988. if(strchr(locationstr,'@')==NULL)
  9989. {
  9990. sscanf(locationstr,
  9991. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9992. protocol, host, &port, path);
  9993. strcpy(user,"anonymous");
  9994. strcpy(password,"");
  9995. }
  9996. else
  9997. {
  9998. //DEBUG_INFO("pch=%s\n", pch);
  9999. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10000. protocol, user, password, host, &port, path);
  10001. }
  10002. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10003. {
  10004. DEBUG_INFO("protocol is not ftp/http ! \n");
  10005. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10006. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10007. goto end;
  10008. }
  10009. if(strncmp(locationstr,"http", 4) == 0)
  10010. {
  10011. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10012. sprintf(ftppath,"/%s", path);
  10013. do
  10014. {
  10015. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10016. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10017. sleep(3);
  10018. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10019. if(!isSuccess)
  10020. {
  10021. DEBUG_INFO("Diagnostics fail.\n");
  10022. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10023. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10024. sleep(retryIntervalInt);
  10025. }
  10026. else
  10027. {
  10028. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10029. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10030. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10031. }
  10032. retriesInt--;
  10033. }while((isSuccess == 0)&&(retriesInt >= 0));
  10034. }
  10035. else
  10036. {
  10037. sscanf(host,"%[^/]%s",host1, path1);
  10038. if(strlen(path) > 0)
  10039. sprintf(ftppath,"/%s", path);
  10040. else
  10041. sprintf(ftppath,"/%s", path1);
  10042. int ftppathlen=strlen(ftppath);
  10043. int i=1;
  10044. char filenametemp[50];
  10045. while(i < ftppathlen)
  10046. {
  10047. int len=ftppathlen-i;
  10048. if(ftppath[len]== 47) // '/' ascll code: 47
  10049. {
  10050. DEBUG_INFO("find '/' all right\n");
  10051. break;
  10052. }
  10053. i=i+1;
  10054. }
  10055. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10056. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10057. filenametemp[i+1] = 0;
  10058. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10059. if(port == 0)
  10060. port = 21;
  10061. do
  10062. {
  10063. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10064. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10065. sleep(3);
  10066. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10067. if(!isSuccess)
  10068. {
  10069. DEBUG_INFO("Diagnostics fail.\n");
  10070. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10071. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10072. sleep(retryIntervalInt);
  10073. }
  10074. else
  10075. {
  10076. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10077. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10078. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10079. }
  10080. retriesInt--;
  10081. }while((!isSuccess)&&(retriesInt >= 0));
  10082. }
  10083. end:
  10084. system("rm -f /mnt/*");
  10085. sleep(5);
  10086. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10087. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10088. interLock.isGetDiagnosticGoing = 0;
  10089. pthread_exit(NULL);
  10090. }
  10091. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10092. {
  10093. mtrace();
  10094. int result = FAIL;
  10095. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10096. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10097. {
  10098. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10099. locallistVersion = -1;
  10100. }
  10101. else
  10102. {
  10103. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10104. OCPP_getListVerion();
  10105. }
  10106. //from db.OCPP_getListVerion
  10107. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10108. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10109. sendGetLocalListVersionConfirmation(uuid,"");
  10110. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10111. return result;
  10112. }
  10113. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10114. {
  10115. mtrace();
  10116. int result = FAIL;
  10117. int connectorIdInt=-1;
  10118. int tempIndex = 0;
  10119. int connectorIdIsNULL, chargingProfileIsNULL;
  10120. char comfirmstr[20]={0};
  10121. char cmdBuf[512];
  10122. json_object *RemoteStartTransaction;
  10123. FILE *fp;
  10124. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10125. if(server_pending == TRUE)
  10126. {
  10127. return 0;
  10128. }
  10129. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10130. RemoteStartTransaction = json_tokener_parse(payload);
  10131. if(!is_error(RemoteStartTransaction))
  10132. {
  10133. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10134. {
  10135. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10136. }
  10137. else
  10138. {
  10139. connectorIdIsNULL = TRUE;
  10140. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10141. {
  10142. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10143. {
  10144. connectorIdIsNULL = FALSE;
  10145. connectorIdInt = (gun_index+1);
  10146. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10147. break;
  10148. }
  10149. }
  10150. }
  10151. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10152. {
  10153. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10154. // Required data
  10155. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10156. // Optional data
  10157. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10158. {
  10159. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10160. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10161. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10162. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10163. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10164. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10165. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10166. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10168. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10170. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10171. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10172. {
  10173. 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")));
  10174. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10175. 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"));
  10176. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10177. 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"));
  10178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10179. 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")));
  10180. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10181. {
  10182. 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++)
  10183. {
  10184. 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"));
  10185. 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"));
  10186. 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)
  10187. 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"));
  10188. }
  10189. }
  10190. }
  10191. }
  10192. else
  10193. {
  10194. chargingProfileIsNULL = TRUE;
  10195. }
  10196. }
  10197. }
  10198. else
  10199. {
  10200. connectorIdIsNULL = TRUE;
  10201. }
  10202. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10203. {
  10204. DEBUG_WARN("Connector id is NULL\n.");
  10205. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10206. goto end;
  10207. }
  10208. /*
  10209. enum _SYSTEM_STATUS
  10210. {
  10211. S_BOOTING = 0,
  10212. S_IDLE, = 1
  10213. S_AUTHORIZING, = 2
  10214. S_REASSIGN_CHECK, = 3
  10215. S_REASSIGN, = 4
  10216. S_PRECHARGE, = 5
  10217. S_PREPARING_FOR_EV, = 6
  10218. S_PREPARING_FOR_EVSE, = 7
  10219. S_CHARGING, = 8
  10220. S_TERMINATING, = 9
  10221. S_COMPLETE, = 10
  10222. S_ALARM, = 11
  10223. S_FAULT = 12
  10224. }
  10225. */
  10226. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10227. {
  10228. //check Transaction active
  10229. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10230. {
  10231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10232. {
  10233. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10234. }
  10235. else
  10236. {
  10237. tempIndex = connectorIdInt -1;
  10238. }
  10239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10240. {
  10241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10242. {
  10243. 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))
  10244. {
  10245. //Reserved
  10246. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10247. }
  10248. 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))
  10249. {
  10250. //Reserved
  10251. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10252. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10253. goto end;
  10254. }
  10255. else
  10256. {
  10257. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10258. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10259. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10260. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10261. {
  10262. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10263. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10264. goto end;
  10265. }
  10266. }//END FOR ELSE
  10267. }
  10268. }// END FOR CHAdeMO_QUANTITY
  10269. }
  10270. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10271. {
  10272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10273. {
  10274. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10275. }
  10276. else
  10277. {
  10278. tempIndex = connectorIdInt -1;
  10279. }
  10280. for (int index = 0; index < CCS_QUANTITY; index++)
  10281. {
  10282. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10283. {
  10284. 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))
  10285. {
  10286. //Reserved
  10287. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10288. }
  10289. 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))
  10290. {
  10291. //Reserved
  10292. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10293. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10294. goto end;
  10295. }
  10296. else
  10297. {
  10298. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10299. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10300. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10301. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10302. {
  10303. DEBUG_WARN("CCS connector not allow start\n.");
  10304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10305. goto end;
  10306. }
  10307. }// END FOR ELSE
  10308. }
  10309. }// END FOR CCS_QUANTITY
  10310. }
  10311. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10312. {
  10313. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10314. {
  10315. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10316. }
  10317. else
  10318. {
  10319. tempIndex = connectorIdInt -1;
  10320. }
  10321. for (int index = 0; index < GB_QUANTITY; index++)
  10322. {
  10323. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10324. {
  10325. 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))
  10326. {
  10327. //Reserved
  10328. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10329. }
  10330. 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))
  10331. {
  10332. //Reserved
  10333. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10335. goto end;
  10336. }
  10337. else
  10338. {
  10339. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10340. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10341. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10342. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10343. {
  10344. DEBUG_WARN("GB connector not allow start\n.");
  10345. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10346. goto end;
  10347. }
  10348. }// END FOR ELSE
  10349. }
  10350. } // END FOR GB_QUANTITY
  10351. }
  10352. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10353. {
  10354. tempIndex = connectorIdInt -1;
  10355. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10356. {
  10357. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10358. {
  10359. 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))
  10360. {
  10361. //Reserved
  10362. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10363. }
  10364. 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))
  10365. {
  10366. //Reserved
  10367. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10368. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10369. goto end;
  10370. }
  10371. else
  10372. {
  10373. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10374. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10375. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10376. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10377. {
  10378. DEBUG_WARN("GB connector not allow start\n.");
  10379. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10380. goto end;
  10381. }
  10382. }// END FOR ELSE
  10383. }
  10384. } // END FOR GB_QUANTITY
  10385. }
  10386. else
  10387. {
  10388. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10389. {
  10390. tempIndex = 2;
  10391. }
  10392. else
  10393. {
  10394. tempIndex = connectorIdInt -1;
  10395. }
  10396. for (int index = 0; index < AC_QUANTITY; index++)
  10397. {
  10398. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10399. {
  10400. 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))
  10401. {
  10402. //Reserved
  10403. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10404. }
  10405. 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))
  10406. {
  10407. //Reserved
  10408. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10409. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10410. goto end;
  10411. }
  10412. else
  10413. {
  10414. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10415. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10416. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10417. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10418. {
  10419. DEBUG_WARN("AC connector not allow start\n.");
  10420. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10421. goto end;
  10422. }
  10423. }//END FOR ELSE
  10424. }
  10425. }// END FOR AC_QUANTITY
  10426. }
  10427. if(chargingProfileIsNULL == FALSE)
  10428. {
  10429. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10430. {
  10431. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10433. //memset idTag
  10434. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10435. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10436. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10437. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10438. // Save profile to file
  10439. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10440. system(cmdBuf);
  10441. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10442. fp = fopen(cmdBuf, "w");
  10443. 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));
  10444. fclose(fp);
  10445. }
  10446. else
  10447. {
  10448. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10449. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10450. }
  10451. }
  10452. else
  10453. {
  10454. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10455. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10456. //memset idTag
  10457. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10458. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10459. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10461. }
  10462. }
  10463. else
  10464. {
  10465. DEBUG_WARN("Connector id over\n.");
  10466. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10467. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10468. }
  10469. end:
  10470. json_object_put(RemoteStartTransaction);
  10471. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10472. {
  10473. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10474. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10475. }
  10476. //OCPP send RemoteStartConfirmation by first.
  10477. sendRemoteStartConfirmation(uuid, comfirmstr);
  10478. return result;
  10479. }
  10480. int handleRemoteStartRequest(char *uuid, char *payload)
  10481. {
  10482. mtrace();
  10483. int result = PASS;
  10484. int connectorIdInt=-1;
  10485. int tempIndex = 0;
  10486. char comfirmstr[20]={0};
  10487. char cmdBuf[512];
  10488. json_object *RemoteStartTransaction;
  10489. FILE *fp;
  10490. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10491. if(server_pending == TRUE)
  10492. {
  10493. result = FAIL;
  10494. }
  10495. RemoteStartTransaction = json_tokener_parse(payload);
  10496. if(!is_error(RemoteStartTransaction))
  10497. {
  10498. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10499. {
  10500. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10501. }
  10502. else
  10503. {
  10504. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10505. {
  10506. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10507. {
  10508. connectorIdInt = (gun_index+1);
  10509. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10510. break;
  10511. }
  10512. }
  10513. }
  10514. if(connectorIdInt == 0)
  10515. {
  10516. DEBUG_WARN("Connector id shall not equal 0.\n");
  10517. result = FAIL;
  10518. }
  10519. else if(connectorIdInt == -1)
  10520. {
  10521. DEBUG_INFO("Connector id does not specific.\n");
  10522. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10523. {
  10524. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10525. // Required data
  10526. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10527. // Optional data
  10528. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10529. {
  10530. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10531. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10532. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10533. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10534. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10535. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10536. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10537. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10538. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10539. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10540. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10541. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10542. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10543. {
  10544. 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")));
  10545. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10546. 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"));
  10547. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10548. 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"));
  10549. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10550. 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")));
  10551. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10552. {
  10553. 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++)
  10554. {
  10555. 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"));
  10556. 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"));
  10557. 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)
  10558. 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"));
  10559. }
  10560. }
  10561. }
  10562. }
  10563. else
  10564. {
  10565. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10566. }
  10567. }
  10568. }
  10569. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10570. {
  10571. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10572. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10573. // Required data
  10574. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10575. // Optional data
  10576. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10577. {
  10578. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10579. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10580. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10581. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10582. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10583. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10584. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10585. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10586. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10587. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10588. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10589. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10591. {
  10592. 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")));
  10593. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10594. 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"));
  10595. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10596. 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"));
  10597. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10598. 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")));
  10599. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10600. {
  10601. 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++)
  10602. {
  10603. 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"));
  10604. 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"));
  10605. 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)
  10606. 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"));
  10607. }
  10608. }
  10609. }
  10610. }
  10611. else
  10612. {
  10613. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10614. }
  10615. }
  10616. else
  10617. {
  10618. DEBUG_WARN("Connector id is over maximun value.\n");
  10619. result = FAIL;
  10620. }
  10621. }
  10622. if(result == PASS)
  10623. {
  10624. if(connectorIdInt > 0)
  10625. {
  10626. //check Transaction active
  10627. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10628. {
  10629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10630. {
  10631. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10632. }
  10633. else
  10634. {
  10635. tempIndex = connectorIdInt -1;
  10636. }
  10637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10638. {
  10639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10640. {
  10641. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10642. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10643. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10644. {
  10645. //Reserved
  10646. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10647. }
  10648. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10649. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10650. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10651. {
  10652. //Reserved
  10653. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10654. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10655. goto end;
  10656. }
  10657. else
  10658. {
  10659. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10660. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10661. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10662. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10663. {
  10664. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10665. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10666. goto end;
  10667. }
  10668. }//END FOR ELSE
  10669. }
  10670. }// END FOR CHAdeMO_QUANTITY
  10671. }
  10672. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10673. {
  10674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10675. {
  10676. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10677. }
  10678. else
  10679. {
  10680. tempIndex = connectorIdInt -1;
  10681. }
  10682. for (int index = 0; index < CCS_QUANTITY; index++)
  10683. {
  10684. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10685. {
  10686. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10687. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10688. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10689. {
  10690. //Reserved
  10691. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10692. }
  10693. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10694. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10695. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10696. {
  10697. //Reserved
  10698. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10700. goto end;
  10701. }
  10702. else
  10703. {
  10704. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10705. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10706. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10707. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10708. {
  10709. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10710. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10711. goto end;
  10712. }
  10713. }// END FOR ELSE
  10714. }
  10715. }// END FOR CCS_QUANTITY
  10716. }
  10717. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10718. {
  10719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10720. {
  10721. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10722. }
  10723. else
  10724. {
  10725. tempIndex = connectorIdInt -1;
  10726. }
  10727. for (int index = 0; index < GB_QUANTITY; index++)
  10728. {
  10729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10730. {
  10731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10732. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10733. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10734. {
  10735. //Reserved
  10736. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10737. }
  10738. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10739. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10740. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10741. {
  10742. //Reserved
  10743. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10744. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10745. goto end;
  10746. }
  10747. else
  10748. {
  10749. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10750. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10751. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10752. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10753. {
  10754. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10755. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10756. goto end;
  10757. }
  10758. }// END FOR ELSE
  10759. }
  10760. } // END FOR GB_QUANTITY
  10761. }
  10762. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10763. {
  10764. tempIndex = connectorIdInt -1;
  10765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10766. {
  10767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10768. {
  10769. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10770. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10771. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10772. {
  10773. //Reserved
  10774. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10775. }
  10776. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10777. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10778. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10779. {
  10780. //Reserved
  10781. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10782. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10783. goto end;
  10784. }
  10785. else
  10786. {
  10787. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10788. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10789. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10790. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10791. {
  10792. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10793. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10794. goto end;
  10795. }
  10796. }// END FOR ELSE
  10797. }
  10798. } // END FOR GB_QUANTITY
  10799. }
  10800. else
  10801. {
  10802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10803. {
  10804. tempIndex = 2;
  10805. }
  10806. else
  10807. {
  10808. tempIndex = connectorIdInt -1;
  10809. }
  10810. for (int index = 0; index < AC_QUANTITY; index++)
  10811. {
  10812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10813. {
  10814. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10815. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10816. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10817. {
  10818. //Reserved
  10819. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10820. }
  10821. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10822. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10823. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10824. {
  10825. //Reserved
  10826. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10827. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10828. goto end;
  10829. }
  10830. else
  10831. {
  10832. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10833. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10834. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10835. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10836. {
  10837. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10838. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10839. goto end;
  10840. }
  10841. }//END FOR ELSE
  10842. }
  10843. }// END FOR AC_QUANTITY
  10844. }
  10845. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10846. {
  10847. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10848. {
  10849. // Save profile to file
  10850. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10851. system(cmdBuf);
  10852. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10853. fp = fopen(cmdBuf, "w");
  10854. 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));
  10855. fclose(fp);
  10856. }
  10857. else
  10858. {
  10859. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10860. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10861. goto end;
  10862. }
  10863. }
  10864. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10865. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10866. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10867. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10868. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10869. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10870. }
  10871. else
  10872. {
  10873. uint8_t isHasIdleConnector = FALSE;
  10874. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10875. {
  10876. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10877. {
  10878. isHasIdleConnector = TRUE;
  10879. break;
  10880. }
  10881. }
  10882. if(isHasIdleConnector == TRUE)
  10883. {
  10884. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10885. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10886. {
  10887. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10888. {
  10889. // Save profile to file
  10890. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10891. system(cmdBuf);
  10892. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10893. fp = fopen(cmdBuf, "w");
  10894. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10895. fclose(fp);
  10896. refreshStartTimer(&clientTime.RemoteStartWait);
  10897. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10898. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10899. }
  10900. else
  10901. {
  10902. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10903. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10904. }
  10905. }
  10906. else
  10907. {
  10908. refreshStartTimer(&clientTime.RemoteStartWait);
  10909. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10910. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10911. }
  10912. }
  10913. else
  10914. {
  10915. DEBUG_INFO("There is not any connector is idle.\n");
  10916. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10917. }
  10918. }
  10919. }
  10920. else
  10921. {
  10922. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10923. }
  10924. end:
  10925. json_object_put(RemoteStartTransaction);
  10926. sendRemoteStartConfirmation(uuid, comfirmstr);
  10927. return result;
  10928. }
  10929. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10930. {
  10931. mtrace();
  10932. int result = FAIL;
  10933. int match = FALSE;
  10934. int GunNO = 0;
  10935. int tempIndex = 0;
  10936. int transactionIdInt=0;
  10937. int transactionIdIsNULL= TRUE;
  10938. char comfirmstr[20];
  10939. json_object *RemoteStopTransaction;
  10940. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10941. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10942. if(server_pending == TRUE)
  10943. {
  10944. return 0;
  10945. }
  10946. RemoteStopTransaction = json_tokener_parse(payload);
  10947. if(!is_error(RemoteStopTransaction))
  10948. {
  10949. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10950. {
  10951. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10952. transactionIdIsNULL = FALSE;
  10953. }
  10954. }
  10955. json_object_put(RemoteStopTransaction);
  10956. if(transactionIdIsNULL == FALSE)
  10957. {
  10958. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10959. {
  10960. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10961. {
  10962. //check Transaction active
  10963. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10964. {
  10965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10966. {
  10967. tempIndex = ((gun_index==2) ? 1: 0);
  10968. }
  10969. else
  10970. {
  10971. tempIndex = gun_index;
  10972. }
  10973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10974. {
  10975. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10976. {
  10977. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10978. {
  10979. match = TRUE;
  10980. GunNO = gun_index;
  10981. }
  10982. }
  10983. }// END FOR CHAdeMO_QUANTITY
  10984. }
  10985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10986. {
  10987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10988. {
  10989. tempIndex = ((gun_index==2) ? 1: 0);
  10990. }
  10991. else
  10992. {
  10993. tempIndex = gun_index;
  10994. }
  10995. for (int index = 0; index < CCS_QUANTITY; index++)
  10996. {
  10997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10998. {
  10999. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11000. {
  11001. match = TRUE;
  11002. GunNO = gun_index;
  11003. }
  11004. }
  11005. }// END FOR CCS_QUANTITY
  11006. }
  11007. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11008. {
  11009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11010. {
  11011. tempIndex = ((gun_index==2) ? 1: 0);
  11012. }
  11013. else
  11014. {
  11015. tempIndex = gun_index;
  11016. }
  11017. for (int index = 0; index < GB_QUANTITY; index++)
  11018. {
  11019. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11020. {
  11021. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11022. {
  11023. match = TRUE;
  11024. GunNO = gun_index;
  11025. }
  11026. }
  11027. }// END FOR GB_QUANTITY
  11028. }
  11029. else if(gunType[gun_index] == GUN_TYPE_DO)
  11030. {
  11031. tempIndex = gun_index;
  11032. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11033. {
  11034. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11035. {
  11036. 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
  11037. {
  11038. match = TRUE;
  11039. GunNO = gun_index;
  11040. }
  11041. }
  11042. }// END FOR GB_QUANTITY
  11043. }
  11044. else
  11045. {
  11046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11047. {
  11048. tempIndex = 2;
  11049. }
  11050. else
  11051. {
  11052. tempIndex = gun_index;
  11053. }
  11054. for (int index = 0; index < AC_QUANTITY; index++)
  11055. {
  11056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11057. {
  11058. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11059. {
  11060. match = TRUE;
  11061. GunNO = gun_index;
  11062. }
  11063. }
  11064. }// END FOR CHAdeMO_QUANTITY
  11065. } // END FOR AC ELSE
  11066. }// CHECK IF ResponseTransactionId == transactionIdInt
  11067. }//END FOR
  11068. if( match == TRUE)
  11069. {
  11070. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11071. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11072. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11073. }
  11074. else
  11075. {
  11076. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11077. }
  11078. }
  11079. else
  11080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11081. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11082. return result;
  11083. }
  11084. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11085. {
  11086. mtrace();
  11087. int result = FAIL;
  11088. int connectorIdInt=0, reservationIdInt=0;
  11089. int tempIndex = 0;
  11090. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11091. char comfirmstr[20]={0};
  11092. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11093. int c = 0;
  11094. char *loc;
  11095. //char *ptr;
  11096. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11097. strcpy(sstrtemp, stringtrimspace(payload));
  11098. //***(1)connectorId ****/
  11099. c=0;
  11100. loc = strstr(sstrtemp, "connectorId");
  11101. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11102. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11103. {
  11104. sstr[c] = loc[strlen("connectorId")+2+c];
  11105. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11106. c++;
  11107. }
  11108. sstr[c] = '\0';
  11109. connectorIdInt = atoi(sstr);
  11110. //***(2)expiryDate ****/
  11111. loc = strstr(sstrtemp, "expiryDate");
  11112. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11113. c = 0;
  11114. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11115. {
  11116. sstr[c] = loc[3+strlen("expiryDate")+c];
  11117. c++;
  11118. }
  11119. sstr[c] = '\0';
  11120. strcpy(expiryDatestr, sstr);
  11121. //***(3)idTag ****/
  11122. loc = strstr(sstrtemp, "idTag");
  11123. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11124. c = 0;
  11125. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11126. {
  11127. sstr[c] = loc[3+strlen("idTag")+c];
  11128. c++;
  11129. }
  11130. sstr[c] = '\0';
  11131. strcpy(idTagstr, sstr);
  11132. //***(4)parentIdTag ****/
  11133. loc = strstr(sstrtemp, "parentIdTag");
  11134. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11135. c = 0;
  11136. if(loc == NULL)
  11137. {
  11138. strcpy(parentIdTagstr, "");
  11139. }
  11140. else
  11141. {
  11142. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11143. {
  11144. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11145. c++;
  11146. }
  11147. sstr[c] = '\0';
  11148. strcpy(parentIdTagstr, sstr);
  11149. }
  11150. //***(5)reservationId ****/
  11151. c=0;
  11152. loc = strstr(sstrtemp, "reservationId");
  11153. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11154. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11155. {
  11156. sstr[c] = loc[strlen("reservationId")+2+c];
  11157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11158. c++;
  11159. }
  11160. sstr[c] = '\0';
  11161. reservationIdInt = atoi(sstr);
  11162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11163. /*
  11164. enum SYSTEM_STATUS
  11165. {
  11166. SYS_MODE_BOOTING = 0,
  11167. SYS_MODE_IDLE = 1,
  11168. SYS_MODE_AUTHORIZING = 2,
  11169. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11170. SYS_MODE_REASSIGN = 4,
  11171. SYS_MODE_PREPARING = 5,
  11172. SYS_MODE_PREPARE_FOR_EV = 6,
  11173. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11174. SYS_MODE_CHARGING = 8,
  11175. SYS_MODE_TERMINATING = 9,
  11176. SYS_MODE_COMPLETE = 10,
  11177. SYS_MODE_ALARM = 11,
  11178. SYS_MODE_FAULT = 12,
  11179. SYS_MODE_RESERVATION = 13,
  11180. SYS_MODE_BOOKING = 14,
  11181. SYS_MODE_MAINTAIN = 15,
  11182. SYS_MODE_DEBUG = 16,
  11183. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11184. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11185. SYS_MODE_UPDATE = 19
  11186. };
  11187. */
  11188. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11189. {
  11190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11191. goto end;
  11192. }
  11193. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11194. {
  11195. //check Transaction active
  11196. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11197. {
  11198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11199. {
  11200. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11201. }
  11202. else
  11203. {
  11204. tempIndex = connectorIdInt -1;
  11205. }
  11206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11207. {
  11208. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11209. {
  11210. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11211. {
  11212. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11213. {
  11214. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11215. {
  11216. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11218. }
  11219. 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'))
  11220. {
  11221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11222. }
  11223. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11224. {
  11225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11226. }
  11227. else
  11228. {
  11229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11230. }
  11231. }
  11232. 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
  11233. {
  11234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11235. }
  11236. }
  11237. else
  11238. {
  11239. //replace reservation
  11240. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11242. }
  11243. }
  11244. } // END FOR CHAdeMO_QUANTITY
  11245. }
  11246. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11247. {
  11248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11249. {
  11250. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11251. }
  11252. else
  11253. {
  11254. tempIndex = connectorIdInt -1;
  11255. }
  11256. for (int index = 0; index < CCS_QUANTITY; index++)
  11257. {
  11258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11259. {
  11260. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11261. {
  11262. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11263. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11264. {
  11265. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11266. {
  11267. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11268. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11269. }
  11270. 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'))
  11271. {
  11272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11273. }
  11274. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11275. {
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11277. }
  11278. else
  11279. {
  11280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11281. }
  11282. }
  11283. 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
  11284. {
  11285. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11286. }
  11287. }
  11288. else
  11289. {
  11290. //replace reservation
  11291. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11293. }
  11294. }
  11295. } // END FOR CCS_QUANTITY
  11296. }
  11297. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11298. {
  11299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11300. {
  11301. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11302. }
  11303. else
  11304. {
  11305. tempIndex = connectorIdInt -1;
  11306. }
  11307. for (int index = 0; index < GB_QUANTITY; index++)
  11308. {
  11309. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11310. {
  11311. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11312. {
  11313. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11314. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11315. {
  11316. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11317. {
  11318. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11319. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11320. }
  11321. 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'))
  11322. {
  11323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11324. }
  11325. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11326. {
  11327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11328. }
  11329. else
  11330. {
  11331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11332. }
  11333. }
  11334. 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
  11335. {
  11336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11337. }
  11338. }
  11339. else
  11340. {
  11341. //replace reservation
  11342. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11343. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11344. }
  11345. }
  11346. }// END FOR GB_QUANTITY
  11347. }
  11348. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11349. {
  11350. tempIndex = connectorIdInt -1;
  11351. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11352. {
  11353. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11354. {
  11355. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11356. {
  11357. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11358. 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
  11359. {
  11360. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11361. {
  11362. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11363. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11364. }
  11365. 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'))
  11366. {
  11367. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11368. }
  11369. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11370. {
  11371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11372. }
  11373. else
  11374. {
  11375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11376. }
  11377. }
  11378. 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
  11379. {
  11380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11381. }
  11382. }
  11383. else
  11384. {
  11385. //replace reservation
  11386. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11387. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11388. }
  11389. }
  11390. }// END FOR GB_QUANTITY
  11391. }
  11392. else
  11393. {
  11394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11395. {
  11396. tempIndex = 2;
  11397. }
  11398. else
  11399. {
  11400. tempIndex = (connectorIdInt -1);
  11401. }
  11402. for (int index = 0; index < AC_QUANTITY; index++)
  11403. {
  11404. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11405. {
  11406. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11407. {
  11408. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11409. {
  11410. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11411. {
  11412. 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))
  11413. {
  11414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11415. }
  11416. else
  11417. {
  11418. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11420. }
  11421. }
  11422. 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'))
  11423. {
  11424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11425. }
  11426. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11427. {
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11429. }
  11430. else
  11431. {
  11432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11433. }
  11434. }
  11435. 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
  11436. {
  11437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11438. }
  11439. }
  11440. else
  11441. {
  11442. //replace reservation
  11443. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11445. }
  11446. }
  11447. } // END FOR AC_QUANTITY
  11448. }
  11449. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11450. }
  11451. else if(connectorIdInt == 0)
  11452. {
  11453. //check Transaction active
  11454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11455. {
  11456. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11457. {
  11458. 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'))
  11459. {
  11460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11461. goto end;
  11462. }
  11463. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11464. {
  11465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11466. goto end;
  11467. }
  11468. 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
  11469. {
  11470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11471. goto end;
  11472. }
  11473. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11474. {
  11475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11476. goto end;
  11477. }
  11478. }
  11479. }// END FOR CHAdeMO_QUANTITY
  11480. for (int index = 0; index < CCS_QUANTITY; index++)
  11481. {
  11482. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11483. {
  11484. 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'))
  11485. {
  11486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11487. goto end;
  11488. }
  11489. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11490. {
  11491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11492. goto end;
  11493. }
  11494. 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
  11495. {
  11496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11497. goto end;
  11498. }
  11499. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11500. {
  11501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11502. goto end;
  11503. }
  11504. }
  11505. } // END FOR CCS_QUANTITY
  11506. for (int index = 0; index < GB_QUANTITY; index++)
  11507. {
  11508. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11509. {
  11510. 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'))
  11511. {
  11512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11513. goto end;
  11514. }
  11515. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11516. {
  11517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11518. goto end;
  11519. }
  11520. 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
  11521. {
  11522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11523. goto end;
  11524. }
  11525. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11526. {
  11527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11528. goto end;
  11529. }
  11530. }
  11531. } // END FOR GB_QUANTITY
  11532. for (int index = 0; index < AC_QUANTITY; index++)
  11533. {
  11534. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11535. {
  11536. 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'))
  11537. {
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11539. goto end;
  11540. }
  11541. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11542. {
  11543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11544. goto end;
  11545. }
  11546. 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
  11547. {
  11548. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11549. goto end;
  11550. }
  11551. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11552. {
  11553. 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))
  11554. {
  11555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11556. goto end;
  11557. }
  11558. }
  11559. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11560. {
  11561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11562. goto end;
  11563. }
  11564. }
  11565. }// END FOR AC_QUANTITY
  11566. //The connectorId is 0
  11567. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11569. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11570. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11571. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11572. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11573. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11574. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11575. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11576. result = TRUE;
  11577. return result;
  11578. }
  11579. else
  11580. {
  11581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11582. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11583. }
  11584. if(strcmp(comfirmstr,"Accepted") == 0)
  11585. {
  11586. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11587. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11588. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11589. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11590. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11591. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11592. result = TRUE;
  11593. return result;
  11594. }
  11595. end:
  11596. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11597. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11598. return result;
  11599. }
  11600. int handleResetRequest(char *uuid, char *payload)
  11601. {
  11602. mtrace();
  11603. int result = FAIL;
  11604. char sstr[10]={0},sstrtemp[30]={ 0 };
  11605. char typestr[10]={0};
  11606. char comfirmstr[20]={0};
  11607. int c = 0;
  11608. char *loc;
  11609. DEBUG_INFO("handleResetRequest...\n");
  11610. strcpy(sstrtemp, stringtrimspace(payload));
  11611. loc = strstr(sstrtemp, "type");
  11612. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11613. c = 0;
  11614. while (loc[3+strlen("type")+c] != '\"')
  11615. {
  11616. sstr[c] = loc[3+strlen("type")+c];
  11617. c++;
  11618. }
  11619. sstr[c] = '\0';
  11620. strcpy(typestr,sstr);
  11621. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11622. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11623. {
  11624. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11625. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11626. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11627. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11628. }
  11629. else
  11630. {
  11631. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11632. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11633. result = PASS;
  11634. }
  11635. sendResetConfirmation(uuid, comfirmstr);
  11636. return result;
  11637. }
  11638. int handleSendLocalListRequest(char *uuid, char *payload)
  11639. {
  11640. mtrace();
  11641. int result = FAIL;
  11642. char comfirmstr[20];
  11643. int checkState_Faulted = FALSE;
  11644. json_object *SendLocalList;
  11645. DEBUG_INFO("handleSendLocalListRequest...\n");
  11646. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11647. {
  11648. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11649. goto end;
  11650. }
  11651. //check Charge Point state
  11652. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11653. {
  11654. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11655. {
  11656. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11657. }
  11658. }
  11659. for (int index = 0; index < CCS_QUANTITY; index++)
  11660. {
  11661. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11662. {
  11663. checkState_Faulted = TRUE; //OCPP Status
  11664. }
  11665. }
  11666. for (int index = 0; index < GB_QUANTITY; index++)
  11667. {
  11668. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11669. {
  11670. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11671. }
  11672. }
  11673. //check Charge Point state
  11674. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11675. {
  11676. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11677. {
  11678. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11679. }
  11680. }
  11681. //check Charge Point state
  11682. for (int index = 0; index < AC_QUANTITY; index++)
  11683. {
  11684. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11685. {
  11686. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11687. }
  11688. }
  11689. if(checkState_Faulted == TRUE)
  11690. {
  11691. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11692. goto end;
  11693. }
  11694. // Parsing payload
  11695. SendLocalList = json_tokener_parse(payload);
  11696. if(!is_error(SendLocalList))
  11697. {
  11698. // Required data
  11699. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11700. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11701. // Optional data
  11702. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11703. {
  11704. //Check UpdateType
  11705. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11706. {
  11707. //Local list full update
  11708. DEBUG_INFO("Local list full update.\n");
  11709. OCPP_getListVerion();
  11710. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11711. {
  11712. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11713. goto end;
  11714. }
  11715. OCPP_cleanLocalList();
  11716. }
  11717. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11718. {
  11719. //Local list different update
  11720. DEBUG_INFO("Local list different update.\n");
  11721. OCPP_getListVerion();
  11722. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11723. {
  11724. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11725. goto end;
  11726. }
  11727. }
  11728. else
  11729. {
  11730. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11731. goto end;
  11732. }
  11733. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11734. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11735. {
  11736. 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")));
  11737. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11738. {
  11739. 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")));
  11740. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11741. 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")));
  11742. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11743. 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")));
  11744. }
  11745. // Add to db
  11746. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11747. {
  11748. //Local list full update
  11749. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11750. idx,
  11751. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11752. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11753. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11754. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11755. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11756. // update list
  11757. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11758. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11759. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11760. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11761. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11762. }
  11763. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11764. {
  11765. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11766. idx,
  11767. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11768. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11769. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11770. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11771. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11772. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11773. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11774. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11775. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11776. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11777. }
  11778. }
  11779. }
  11780. else
  11781. {
  11782. //Check UpdateType
  11783. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11784. {
  11785. //Local list full update
  11786. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11787. OCPP_cleanLocalList();
  11788. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11789. goto end;
  11790. }
  11791. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11792. {
  11793. //Local list different update
  11794. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11795. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11796. goto end;
  11797. }
  11798. }
  11799. result = PASS;
  11800. }
  11801. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11802. end:
  11803. json_object_put(SendLocalList);
  11804. sendSendLocalListConfirmation(uuid, comfirmstr);
  11805. return result;
  11806. }
  11807. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11808. {
  11809. mtrace();
  11810. int result = FAIL;
  11811. struct StructSetChargingProfile SetProfileReq = {0};
  11812. int tempchargingProfileIdInt;
  11813. int tempstackLevelInt;
  11814. int chargingSchedulePeriodCount = 0;
  11815. char comfirmstr[20]={0};
  11816. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11817. char rmFileCmd[128]={0};
  11818. int profileQuantity = 0;
  11819. int isReplaceable = FALSE;
  11820. json_object *SetChargingProfile;
  11821. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11822. SetChargingProfile = json_tokener_parse(payload);
  11823. if(!is_error(SetChargingProfile))
  11824. {
  11825. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11826. {
  11827. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11828. }
  11829. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11830. {
  11831. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11832. {
  11833. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11834. }
  11835. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11836. {
  11837. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11838. }
  11839. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11840. {
  11841. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11842. }
  11843. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11844. {
  11845. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11846. }
  11847. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11848. {
  11849. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11850. }
  11851. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11852. {
  11853. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11854. }
  11855. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11856. {
  11857. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11858. }
  11859. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11860. {
  11861. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11862. }
  11863. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11864. {
  11865. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11866. {
  11867. 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")));
  11868. }
  11869. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11870. {
  11871. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11872. }
  11873. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11874. {
  11875. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11876. }
  11877. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11878. {
  11879. 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")));
  11880. }
  11881. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11882. {
  11883. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11884. if(chargingSchedulePeriodCount <= 10)
  11885. {
  11886. 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++)
  11887. {
  11888. 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)
  11889. {
  11890. 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"));
  11891. }
  11892. 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)
  11893. {
  11894. 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"));
  11895. }
  11896. 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)
  11897. {
  11898. 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"));
  11899. }
  11900. }
  11901. }
  11902. }
  11903. }
  11904. }
  11905. }
  11906. // Profile periods quantity check
  11907. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11908. {
  11909. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11910. goto end;
  11911. }
  11912. // Check invalid limit
  11913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11914. {
  11915. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11916. {
  11917. 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)))) ||
  11918. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11919. {
  11920. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11921. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11922. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11923. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11924. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11925. goto end;
  11926. }
  11927. }
  11928. }
  11929. else
  11930. {
  11931. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11932. {
  11933. 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))
  11934. {
  11935. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11936. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11937. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11938. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11939. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11940. goto end;
  11941. }
  11942. }
  11943. }
  11944. // Profile purpose info check
  11945. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11946. {
  11947. FILE *fp;
  11948. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11949. if(SetProfileReq.ConnectorId != 0)
  11950. {
  11951. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11952. goto end;
  11953. }
  11954. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11955. if (!fp)
  11956. {
  11957. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11958. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11959. }
  11960. else
  11961. {
  11962. char *line = NULL;
  11963. size_t len = 0;
  11964. while(getline(&line, &len, fp) != -1)
  11965. {
  11966. json_object *obj = NULL;
  11967. obj = json_tokener_parse(line);
  11968. if(is_error(obj))
  11969. {
  11970. DEBUG_ERROR("Parse txProfile from file error.\n");
  11971. }
  11972. else
  11973. {
  11974. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11975. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11976. {
  11977. profileQuantity += 1;
  11978. }
  11979. else
  11980. isReplaceable = TRUE;
  11981. }
  11982. }
  11983. }
  11984. fclose(fp);
  11985. }
  11986. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11987. {
  11988. FILE *fp;
  11989. char filename[128]={0};
  11990. int tmpProfileQuantity;
  11991. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11992. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11993. {
  11994. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11995. goto end;
  11996. }
  11997. if(SetProfileReq.ConnectorId == 0)
  11998. {
  11999. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12000. {
  12001. tmpProfileQuantity = 0;
  12002. memset(filename, 0, ARRAY_SIZE(filename));
  12003. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12004. fp = fopen(filename, "r");
  12005. if (!fp)
  12006. {
  12007. DEBUG_INFO("%s does not create.\n", filename);
  12008. fp = fopen(filename, "w+");
  12009. }
  12010. else
  12011. {
  12012. char *line = NULL;
  12013. size_t len = 0;
  12014. while(getline(&line, &len, fp) != -1)
  12015. {
  12016. json_object *obj = NULL;
  12017. obj = json_tokener_parse(line);
  12018. if(is_error(obj))
  12019. {
  12020. DEBUG_ERROR("Parse txProfile from file error.\n");
  12021. }
  12022. else
  12023. {
  12024. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12025. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12026. {
  12027. tmpProfileQuantity += 1;
  12028. }
  12029. else
  12030. isReplaceable = TRUE;
  12031. }
  12032. }
  12033. }
  12034. fclose(fp);
  12035. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12036. }
  12037. }
  12038. else
  12039. {
  12040. memset(filename, 0, ARRAY_SIZE(filename));
  12041. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12042. fp = fopen(filename, "r");
  12043. if (!fp)
  12044. {
  12045. DEBUG_INFO("%s does not create.\n", filename);
  12046. fp = fopen(filename, "w+");
  12047. }
  12048. else
  12049. {
  12050. char *line = NULL;
  12051. size_t len = 0;
  12052. while(getline(&line, &len, fp) != -1)
  12053. {
  12054. json_object *obj = NULL;
  12055. obj = json_tokener_parse(line);
  12056. if(is_error(obj))
  12057. {
  12058. DEBUG_ERROR("Parse txProfile from file error.\n");
  12059. }
  12060. else
  12061. {
  12062. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12063. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12064. {
  12065. profileQuantity += 1;
  12066. }
  12067. else
  12068. isReplaceable = TRUE;
  12069. }
  12070. }
  12071. }
  12072. fclose(fp);
  12073. }
  12074. }
  12075. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12076. {
  12077. int isMatchTransactiodId= FALSE;
  12078. FILE *fp;
  12079. char filename[128]={0};
  12080. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12081. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12082. if(SetProfileReq.ConnectorId == 0)
  12083. {
  12084. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12085. goto end;
  12086. }
  12087. int tempIndex = 0;
  12088. //check Transaction active
  12089. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12090. {
  12091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12092. {
  12093. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12094. }
  12095. else
  12096. {
  12097. tempIndex = SetProfileReq.ConnectorId -1;
  12098. }
  12099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12100. {
  12101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12102. {
  12103. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12104. {
  12105. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12106. {
  12107. isMatchTransactiodId = TRUE;
  12108. break;
  12109. }
  12110. }
  12111. }
  12112. }
  12113. }
  12114. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12115. {
  12116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12117. {
  12118. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12119. }
  12120. else
  12121. {
  12122. tempIndex = SetProfileReq.ConnectorId -1;
  12123. }
  12124. for (int index = 0; index < CCS_QUANTITY; index++)
  12125. {
  12126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12127. {
  12128. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12129. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12130. {
  12131. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12132. {
  12133. isMatchTransactiodId = TRUE;
  12134. break;
  12135. }
  12136. }
  12137. }
  12138. }
  12139. }
  12140. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12141. {
  12142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12143. {
  12144. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12145. }
  12146. else
  12147. {
  12148. tempIndex = SetProfileReq.ConnectorId -1;
  12149. }
  12150. for (int index = 0; index < GB_QUANTITY; index++)
  12151. {
  12152. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12153. {
  12154. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12155. {
  12156. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12157. {
  12158. isMatchTransactiodId = TRUE;
  12159. break;
  12160. }
  12161. }
  12162. }
  12163. }
  12164. }
  12165. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12166. {
  12167. tempIndex = SetProfileReq.ConnectorId -1;
  12168. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12169. {
  12170. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12171. {
  12172. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12173. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12174. {
  12175. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12176. {
  12177. isMatchTransactiodId = TRUE;
  12178. break;
  12179. }
  12180. }
  12181. }
  12182. }
  12183. }
  12184. else
  12185. {
  12186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12187. {
  12188. tempIndex = 2;
  12189. }
  12190. else
  12191. {
  12192. tempIndex = (SetProfileReq.ConnectorId -1);
  12193. }
  12194. for (int index = 0; index < AC_QUANTITY; index++)
  12195. {
  12196. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12197. {
  12198. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12199. {
  12200. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12201. {
  12202. isMatchTransactiodId = TRUE;
  12203. break;
  12204. }
  12205. }
  12206. }
  12207. }
  12208. }
  12209. //check Transaction active
  12210. if(isMatchTransactiodId == FALSE)
  12211. {
  12212. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12213. goto end;
  12214. }
  12215. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12216. {
  12217. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12218. goto end;
  12219. }
  12220. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12221. fp = fopen(filename, "r");
  12222. if (!fp)
  12223. {
  12224. DEBUG_INFO("%s does not create.\n", filename);
  12225. fp = fopen(filename, "w+");
  12226. }
  12227. else
  12228. {
  12229. char *line = NULL;
  12230. size_t len = 0;
  12231. while(getline(&line, &len, fp) != -1)
  12232. {
  12233. json_object *obj = NULL;
  12234. obj = json_tokener_parse(line);
  12235. if(is_error(obj))
  12236. {
  12237. DEBUG_ERROR("Parse txProfile from file error.\n");
  12238. }
  12239. else
  12240. {
  12241. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12242. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12243. {
  12244. profileQuantity += 1;
  12245. }
  12246. else
  12247. isReplaceable = TRUE;
  12248. }
  12249. }
  12250. }
  12251. fclose(fp);
  12252. }
  12253. // Check ChargeProfileMaxStackLevel
  12254. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12255. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12256. {
  12257. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12258. goto end;
  12259. }
  12260. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12261. {
  12262. FILE *fp;
  12263. char dataLine[4096]={0};
  12264. char fnametemp[128]={0};
  12265. int tmpProfileQuantity;
  12266. //Check ChargePointMaxProfile.json exit
  12267. profileQuantity = 0;
  12268. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12269. {
  12270. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12271. //Check Charging Profile Count
  12272. tmpProfileQuantity = 0;
  12273. while(fscanf(fp, "%s", dataLine) != EOF)
  12274. {
  12275. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12276. {
  12277. profileQuantity += 1;
  12278. tmpProfileQuantity += 1;
  12279. }
  12280. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12281. }
  12282. fclose(fp);
  12283. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12284. }
  12285. //Check TxDefaultProfile_%d.json
  12286. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12287. {
  12288. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12289. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12290. if((access(fnametemp,F_OK))!=-1)
  12291. {
  12292. fp = fopen(fnametemp, "r");
  12293. //Check Charging Profile Count
  12294. tmpProfileQuantity = 0;
  12295. while(fscanf(fp, "%s", dataLine) != EOF)
  12296. {
  12297. //DEBUG_INFO("word=%s\n",word);
  12298. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12299. {
  12300. profileQuantity += 1;
  12301. tmpProfileQuantity += 1;
  12302. }
  12303. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12304. }
  12305. fclose(fp);
  12306. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12307. }
  12308. }
  12309. //Check TxProfile_%d.json
  12310. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12311. {
  12312. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12313. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12314. if((access(fnametemp,F_OK))!=-1)
  12315. {
  12316. fp = fopen(fnametemp, "r");
  12317. //Check Charging Profile Count
  12318. tmpProfileQuantity = 0;
  12319. while(fscanf(fp, "%s", dataLine) != EOF)
  12320. {
  12321. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12322. {
  12323. profileQuantity += 1;
  12324. tmpProfileQuantity += 1;
  12325. }
  12326. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12327. }
  12328. fclose(fp);
  12329. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12330. }
  12331. }
  12332. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12333. if((profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12334. {
  12335. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12336. goto end;
  12337. }
  12338. }
  12339. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12340. //**********************************Write to File********************************************************/
  12341. {
  12342. FILE *infile;
  12343. FILE *outfile;
  12344. char dataLine[4096]={0};
  12345. char filename[128]={0};
  12346. int chkChar=0;
  12347. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12348. {
  12349. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12350. {
  12351. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12352. }
  12353. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12354. {
  12355. if(SetProfileReq.ConnectorId==0)
  12356. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12357. else
  12358. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12359. }
  12360. else
  12361. {
  12362. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12363. }
  12364. infile = fopen (filename, "r");
  12365. outfile = fopen (tempfile, "w");
  12366. chkChar = fgetc(infile);
  12367. rewind(infile);
  12368. if(chkChar == EOF)
  12369. {
  12370. // Profile is empty
  12371. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12372. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12373. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12374. fclose(infile);
  12375. fclose(outfile);
  12376. sprintf(rmFileCmd,"rm -f %s",filename);
  12377. system(rmFileCmd);
  12378. rename(tempfile, filename);
  12379. }
  12380. else
  12381. {
  12382. // Profile is not empty
  12383. int ChargingProfileAdded = FALSE;
  12384. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12385. {
  12386. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12387. json_object *tmpChargingProfile;
  12388. tmpChargingProfile = json_tokener_parse(dataLine);
  12389. if(!is_error(SetChargingProfile))
  12390. {
  12391. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12392. {
  12393. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12394. {
  12395. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12396. }
  12397. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12398. {
  12399. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12400. }
  12401. }
  12402. }
  12403. json_object_put(tmpChargingProfile);
  12404. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12405. {
  12406. if(ChargingProfileAdded == FALSE)
  12407. {
  12408. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12409. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12410. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12411. ChargingProfileAdded = TRUE;
  12412. }
  12413. }
  12414. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12415. {
  12416. if(ChargingProfileAdded == FALSE)
  12417. {
  12418. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12419. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12420. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12421. ChargingProfileAdded = TRUE;
  12422. }
  12423. }
  12424. else
  12425. {
  12426. fprintf(outfile,"%s\n",dataLine);
  12427. if(ChargingProfileAdded == FALSE)
  12428. {
  12429. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12430. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12431. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12432. ChargingProfileAdded = TRUE;
  12433. }
  12434. }
  12435. } // end of while loop
  12436. fclose(infile);
  12437. fclose(outfile);
  12438. sprintf(rmFileCmd,"rm -f %s",filename);
  12439. system(rmFileCmd);
  12440. rename(tempfile, filename);
  12441. }
  12442. }
  12443. sleep(1);
  12444. result = TRUE;
  12445. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12446. }
  12447. end:
  12448. json_object_put(SetChargingProfile);
  12449. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12450. {
  12451. if(SetProfileReq.ConnectorId == 0)
  12452. {
  12453. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12454. {
  12455. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12456. }
  12457. }
  12458. else
  12459. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12460. }
  12461. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12462. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12463. return result;
  12464. }
  12465. int handleTriggerMessageRequest(char *uuid, char *payload)
  12466. {
  12467. mtrace();
  12468. int result = FAIL;
  12469. int connectorIdIsNULL = FALSE;
  12470. int connectorIdInt =0;
  12471. char sstr[40]={0},sstrtemp[100]={ 0 };
  12472. char requestedMessagestr[40]={0};
  12473. char comfirmstr[20]={0};
  12474. int c = 0;
  12475. char *loc;
  12476. DEBUG_INFO("handleTriggerMessageRequest\n");
  12477. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12478. strcpy(sstrtemp, stringtrimspace(payload));
  12479. c = 0;
  12480. loc = strstr(sstrtemp, "requestedMessage");
  12481. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12482. {
  12483. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12484. c++;
  12485. }
  12486. sstr[c] = '\0';
  12487. strcpy(requestedMessagestr, sstr);
  12488. c = 0;
  12489. loc = strstr(sstrtemp, "connectorId");
  12490. if(loc == NULL)
  12491. {
  12492. connectorIdIsNULL = TRUE;
  12493. }
  12494. else
  12495. {
  12496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12497. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12498. {
  12499. sstr[c] = loc[strlen("connectorId")+2+c];
  12500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12501. c++;
  12502. }
  12503. sstr[c] = '\0';
  12504. connectorIdInt = atoi(sstr);
  12505. }
  12506. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12507. {
  12508. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12509. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12510. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12511. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12512. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12513. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12514. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12515. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12516. {
  12517. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12518. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12519. return TRUE;
  12520. }
  12521. else
  12522. {
  12523. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12524. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12525. }
  12526. }
  12527. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12528. {
  12529. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12530. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12531. return TRUE;
  12532. }
  12533. //==========================
  12534. // Trigger message
  12535. //==========================
  12536. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12537. {
  12538. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12539. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12540. {
  12541. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12542. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12543. }
  12544. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12545. }
  12546. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12547. {
  12548. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12549. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12550. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12551. }
  12552. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12553. {
  12554. //sendBootNotificationRequest();
  12555. server_sign = FALSE;
  12556. }
  12557. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12558. {
  12559. refreshStartTimer(&clientTime.Heartbeat);
  12560. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12561. }
  12562. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12563. {
  12564. if(connectorIdIsNULL == FALSE)
  12565. {
  12566. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12567. {
  12568. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12569. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12570. }
  12571. }
  12572. else
  12573. {
  12574. for(int idx=0;idx< gunTotalNumber;idx++)
  12575. {
  12576. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12577. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12578. }
  12579. }
  12580. }
  12581. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12582. {
  12583. if(connectorIdIsNULL == FALSE)
  12584. {
  12585. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12586. {
  12587. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12588. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12589. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12590. }
  12591. }
  12592. else
  12593. {
  12594. for(int idx=0;idx< gunTotalNumber;idx++)
  12595. {
  12596. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12597. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12598. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12599. }
  12600. }
  12601. }
  12602. return result;
  12603. }
  12604. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12605. {
  12606. mtrace();
  12607. int result = FAIL;
  12608. int connectorIdInt =0;
  12609. char comfirmstr[20]={0};
  12610. int tempIndex = 0;
  12611. json_object *UnlockConnector;
  12612. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12613. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12614. UnlockConnector = json_tokener_parse(payload);
  12615. if(!is_error(UnlockConnector))
  12616. {
  12617. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12618. {
  12619. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12620. }
  12621. }
  12622. json_object_put(UnlockConnector);
  12623. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12624. if(gunTotalNumber == 0)
  12625. {
  12626. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12627. goto end;
  12628. }
  12629. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12630. {
  12631. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12632. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12633. goto end;
  12634. }
  12635. else
  12636. {
  12637. //check Transaction active
  12638. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12639. {
  12640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12641. {
  12642. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12643. }
  12644. else
  12645. {
  12646. tempIndex = connectorIdInt -1;
  12647. }
  12648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12649. {
  12650. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12651. {
  12652. //stop Transaction
  12653. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12654. }
  12655. }
  12656. }
  12657. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12658. {
  12659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12660. {
  12661. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12662. }
  12663. else
  12664. {
  12665. tempIndex = connectorIdInt -1;
  12666. }
  12667. for (int index = 0; index < CCS_QUANTITY; index++)
  12668. {
  12669. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12670. {
  12671. //stop Transaction
  12672. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12673. }
  12674. }
  12675. }
  12676. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12677. {
  12678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12679. {
  12680. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12681. }
  12682. else
  12683. {
  12684. tempIndex = connectorIdInt -1;
  12685. }
  12686. for (int index = 0; index < GB_QUANTITY; index++)
  12687. {
  12688. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12689. {
  12690. //stop Transaction
  12691. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12692. }
  12693. }
  12694. }
  12695. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12696. {
  12697. tempIndex = connectorIdInt -1;
  12698. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12699. {
  12700. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12701. {
  12702. //stop Transaction
  12703. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12704. }
  12705. }
  12706. }
  12707. else
  12708. {
  12709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12710. {
  12711. tempIndex = 2;
  12712. }
  12713. else
  12714. {
  12715. tempIndex = connectorIdInt-1;
  12716. }
  12717. for (int index = 0; index < AC_QUANTITY; index++)
  12718. {
  12719. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12720. {
  12721. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12722. }
  12723. }
  12724. }
  12725. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12726. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12727. result = TRUE;
  12728. return result;
  12729. }
  12730. end:
  12731. //json_object_put(obj); --- remove temporally
  12732. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12733. return result;
  12734. }
  12735. static char UpdateFirmwarepayloadData[300]={0};
  12736. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12737. {
  12738. mtrace();
  12739. int result = FAIL;
  12740. pthread_t t;
  12741. sendUpdateFirmwareConfirmation(uuid);
  12742. memset(UpdateFirmwarepayloadData, 0, 300);
  12743. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12744. if(!interLock.isUpdateFirmwareGoing)
  12745. {
  12746. interLock.isUpdateFirmwareGoing = 1;
  12747. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12748. sleep(1);
  12749. }
  12750. else
  12751. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12752. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12753. return result;
  12754. }
  12755. void *UpdateFirmwareProcess(void *data)
  12756. {
  12757. pthread_detach(pthread_self());
  12758. mtrace();
  12759. int retriesInt =0, retryIntervalInt=0;
  12760. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12761. int port=0;
  12762. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12763. int isSuccess = 0;
  12764. char ftpbuf[512];
  12765. char temp[100];
  12766. char * pch;
  12767. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12768. json_object *UpdateFirmware;
  12769. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12770. if(!is_error(UpdateFirmware))
  12771. {
  12772. // Required data
  12773. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12774. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12775. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12776. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12777. // Optional data
  12778. if(json_object_object_get(UpdateFirmware, "retries"))
  12779. {
  12780. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12781. }
  12782. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12783. {
  12784. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12785. }
  12786. }
  12787. json_object_put(UpdateFirmware);
  12788. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12789. memset(path, 0, ARRAY_SIZE(path));
  12790. // Wait retrieveData
  12791. if(strlen(retrieveDatestr) > 10)
  12792. {
  12793. do
  12794. {
  12795. sleep(1);
  12796. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12797. }
  12798. // Ready to download
  12799. system("rm -f /mnt/*");
  12800. if(strncmp(locationstr,"http", 4) == 0)
  12801. {
  12802. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12803. sprintf(ftppath,"/%s", path);
  12804. DEBUG_INFO("locationstr: %s\n", locationstr);
  12805. DEBUG_INFO("protocol: %s\n",protocol);
  12806. DEBUG_INFO("host: %s\n",host);
  12807. DEBUG_INFO("path: %s\n",path);
  12808. DEBUG_INFO("ftppath: %s\n",ftppath);
  12809. int ftppathlen=strlen(ftppath);
  12810. int i=1;
  12811. char filenametemp[50];
  12812. while(i < ftppathlen)
  12813. {
  12814. int len=ftppathlen-i;
  12815. if(ftppath[len]== 47) // '/' ascll code: 47
  12816. {
  12817. DEBUG_INFO("compare '/' all right\n");
  12818. break;
  12819. }
  12820. i=i+1;
  12821. }
  12822. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12823. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12824. filenametemp[i+1] = 0;
  12825. do
  12826. {
  12827. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12828. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12829. sleep(1);
  12830. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12831. if(!isSuccess)
  12832. {
  12833. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12834. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12835. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12836. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12837. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12838. }
  12839. else
  12840. {
  12841. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12842. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12843. }
  12844. retriesInt--;
  12845. }while((isSuccess == 0)&&(retriesInt >= 0));
  12846. }
  12847. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12848. {
  12849. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12850. memset(temp, 0, ARRAY_SIZE(temp));
  12851. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12852. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12853. int ftppathlen=strlen(ftpbuf);
  12854. int i=1;
  12855. char filenametemp[50];
  12856. while(i < ftppathlen)
  12857. {
  12858. int len=ftppathlen-i;
  12859. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12860. {
  12861. DEBUG_INFO(" compare '/' all right\n");
  12862. break;
  12863. }
  12864. i=i+1;
  12865. }
  12866. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12867. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12868. filenametemp[i+1] = 0;
  12869. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12870. pch=strchr(temp,'@');
  12871. if(pch==NULL)
  12872. {
  12873. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12874. protocol, host, &port, path);
  12875. strcpy(user,"anonymous");
  12876. strcpy(password,"");
  12877. }
  12878. else
  12879. {
  12880. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12881. protocol, user, password, host, &port, path);
  12882. }
  12883. sscanf(host,"%[^/]%s",host1, path1);
  12884. sprintf(ftppath,"%s", path1);
  12885. //DEBUG_INFO("protocol =%s\n",protocol);
  12886. //DEBUG_INFO("user =%s\n",user);
  12887. //DEBUG_INFO("password =%s\n",password);
  12888. //DEBUG_INFO("host1 =%s\n",host1);
  12889. //DEBUG_INFO("port =%d\n",port);
  12890. //DEBUG_INFO("path1 =%s\n",path1);
  12891. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12892. //ftpFile(host, user, password, port, ftppath, fname);
  12893. //download firmware pthred
  12894. if(port == 0)
  12895. {
  12896. port = 21;
  12897. }
  12898. do
  12899. {
  12900. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12901. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12902. sleep(1);
  12903. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12904. if(!isSuccess)
  12905. {
  12906. //BulldogUtil.sleepMs(interval*1000);
  12907. DEBUG_INFO("Update firmware request and download file fail.\n");
  12908. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12909. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12910. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12911. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12912. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12913. }
  12914. else
  12915. {
  12916. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12917. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12918. }
  12919. retriesInt--;
  12920. }while((!isSuccess)&&(retriesInt >= 0));
  12921. }
  12922. else
  12923. {
  12924. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12925. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12926. sleep(1);
  12927. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12928. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12929. }
  12930. // OCPPPH only, must announce CSU upgrade firmware
  12931. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12932. interLock.isUpdateFirmwareGoing = 0;
  12933. pthread_exit(NULL);
  12934. }
  12935. int handleCertificateSignedRequest(char *uuid, char *payload)
  12936. {
  12937. mtrace();
  12938. int result = PASS;
  12939. json_object *CertificateSigned;
  12940. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12941. CertificateSigned = json_tokener_parse(payload);
  12942. if(!is_error(CertificateSigned))
  12943. {
  12944. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12945. }
  12946. json_object_put(CertificateSigned);
  12947. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12948. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12949. fclose(fp);
  12950. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12951. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12952. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12953. sendCertificateSignedConfirmation(uuid);
  12954. return result;
  12955. }
  12956. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12957. {
  12958. mtrace();
  12959. int result = PASS;
  12960. json_object *DeleteCertificate;
  12961. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12962. DeleteCertificate = json_tokener_parse(payload);
  12963. if(!is_error(DeleteCertificate))
  12964. {
  12965. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12966. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12967. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12968. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12969. }
  12970. json_object_put(DeleteCertificate);
  12971. /*
  12972. * TODO: Delete certificateSigned process
  12973. */
  12974. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12975. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12976. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12977. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12978. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12979. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12980. sendDeleteCertificateConfirmation(uuid);
  12981. return result;
  12982. }
  12983. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12984. {
  12985. mtrace();
  12986. int result = PASS;
  12987. json_object *ExtendedTriggerMessage;
  12988. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12989. ExtendedTriggerMessage = json_tokener_parse(payload);
  12990. if(!is_error(ExtendedTriggerMessage))
  12991. {
  12992. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12993. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12994. {
  12995. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12996. }
  12997. else
  12998. {
  12999. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13000. }
  13001. }
  13002. json_object_put(ExtendedTriggerMessage);
  13003. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13004. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13005. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13006. {
  13007. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13008. }
  13009. else
  13010. {
  13011. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13012. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13013. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13014. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13015. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13016. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13017. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13018. {
  13019. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13020. }
  13021. else
  13022. {
  13023. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13024. }
  13025. }
  13026. sendExtendedTriggerMessageConfirmation(uuid);
  13027. //==========================
  13028. // Trigger message
  13029. //==========================
  13030. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13031. {
  13032. //sendBootNotificationRequest();
  13033. server_sign = FALSE;
  13034. }
  13035. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13036. {
  13037. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13038. }
  13039. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13040. {
  13041. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13042. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13043. {
  13044. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13045. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13046. }
  13047. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13048. }
  13049. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13050. {
  13051. refreshStartTimer(&clientTime.Heartbeat);
  13052. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13053. }
  13054. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13055. {
  13056. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13057. {
  13058. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13059. }
  13060. else
  13061. {
  13062. for(int idx=0;idx< gunTotalNumber;idx++)
  13063. {
  13064. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13065. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13066. }
  13067. }
  13068. }
  13069. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13070. {
  13071. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13072. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13073. {
  13074. 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\" &");
  13075. }
  13076. }
  13077. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13078. {
  13079. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13080. {
  13081. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13082. }
  13083. else
  13084. {
  13085. for(int idx=0;idx< gunTotalNumber;idx++)
  13086. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13087. }
  13088. }
  13089. return result;
  13090. }
  13091. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13092. {
  13093. mtrace();
  13094. int result = PASS;
  13095. json_object *GetInstalledCertificateIds;
  13096. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13097. GetInstalledCertificateIds = json_tokener_parse(payload);
  13098. if(!is_error(GetInstalledCertificateIds))
  13099. {
  13100. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13101. }
  13102. json_object_put(GetInstalledCertificateIds);
  13103. /*
  13104. * TODO: Return installed certificate process
  13105. */
  13106. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13107. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13108. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13109. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13110. sendGetInstalledCertificateIdsConfirmation(uuid);
  13111. return result;
  13112. }
  13113. int handleGetLogRequest(char *uuid, char *payload)
  13114. {
  13115. mtrace();
  13116. int result = PASS;
  13117. json_object *GetLog;
  13118. DEBUG_INFO("handleGetLogRequest...\n");
  13119. GetLog = json_tokener_parse(payload);
  13120. if(!is_error(GetLog))
  13121. {
  13122. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13123. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13124. if(json_object_object_get(GetLog, "retries") != NULL)
  13125. {
  13126. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13127. }
  13128. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13129. {
  13130. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13131. }
  13132. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13133. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13134. {
  13135. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13136. }
  13137. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13138. {
  13139. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13140. }
  13141. }
  13142. json_object_put(GetLog);
  13143. /*
  13144. * TODO: Upload log process
  13145. */
  13146. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13147. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13148. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13149. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13150. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13151. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13152. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13153. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13154. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13155. sendGetLogConfirmation(uuid);
  13156. return result;
  13157. }
  13158. int handleInstallCertificateRequest(char *uuid, char *payload)
  13159. {
  13160. mtrace();
  13161. int result = PASS;
  13162. json_object *InstallCertificate;
  13163. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13164. InstallCertificate = json_tokener_parse(payload);
  13165. if(!is_error(InstallCertificate))
  13166. {
  13167. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13168. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13169. /*
  13170. * TODO: Install certificate process
  13171. */
  13172. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13173. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13174. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13175. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13176. sendInstallCertificateConfirmation(uuid);
  13177. }
  13178. json_object_put(InstallCertificate);
  13179. return result;
  13180. }
  13181. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13182. {
  13183. mtrace();
  13184. int result = PASS;
  13185. json_object *SignedUpdateFirmware;
  13186. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13187. SignedUpdateFirmware = json_tokener_parse(payload);
  13188. if(!is_error(SignedUpdateFirmware))
  13189. {
  13190. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13191. {
  13192. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13193. }
  13194. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13195. {
  13196. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13197. }
  13198. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13199. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13200. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13201. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13202. {
  13203. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13204. }
  13205. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13206. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13207. }
  13208. json_object_put(SignedUpdateFirmware);
  13209. /*
  13210. * TODO: Upgrade firmware process
  13211. */
  13212. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13213. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13214. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13215. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13216. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13217. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13218. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13219. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13220. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13221. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13222. sendInstallCertificateConfirmation(uuid);
  13223. return result;
  13224. }
  13225. int handleUnknownRequest(char *uuid, char *payload)
  13226. {
  13227. mtrace();
  13228. int result = PASS;
  13229. DEBUG_INFO("handleUnknownRequest...\n");
  13230. sendUnknownConfirmation(uuid);
  13231. result = PASS;
  13232. return result;
  13233. }
  13234. //==========================================
  13235. // Handle server response routine
  13236. //==========================================
  13237. void handleAuthorizeResponse(char *payload, int gun_index)
  13238. {
  13239. mtrace();
  13240. char expiryDatestr[30]={0};
  13241. char parentIdTagstr[20]={0};
  13242. char statusstr[20]={0};
  13243. int expiryDateISNULL=FALSE;
  13244. int parentIdTagISNULL=FALSE;
  13245. DEBUG_INFO("handleAuthorizeResponse...\n");
  13246. json_object *Authorize;
  13247. Authorize = json_tokener_parse(payload);
  13248. if(!is_error(Authorize))
  13249. {
  13250. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13251. {
  13252. // Required data
  13253. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13254. // Optional data
  13255. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13256. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13257. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13258. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13259. }
  13260. }
  13261. json_object_put(Authorize);
  13262. if(expiryDateISNULL == FALSE)
  13263. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13264. if(parentIdTagISNULL == FALSE)
  13265. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13266. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13267. //Update idTag information to authorization cache if supproted
  13268. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13269. {
  13270. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13271. }
  13272. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13273. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13274. authorizeRetryTimes = 0;
  13275. }
  13276. void handleBootNotificationResponse(char *payload, int gun_index)
  13277. {
  13278. mtrace();
  13279. char statusStr[12]={0};
  13280. char currentTimeStr[30]={0};
  13281. int intervalInt = 0;
  13282. DEBUG_INFO("handleBootNotificationResponse...\n");
  13283. json_object *BootNotification;
  13284. BootNotification = json_tokener_parse(payload);
  13285. if(!is_error(BootNotification))
  13286. {
  13287. // Required data
  13288. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13289. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13290. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13291. }
  13292. json_object_put(BootNotification);
  13293. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13294. BootNotificationInterval = intervalInt;
  13295. //write back to ShmOCPP16DataPH->BootNotification
  13296. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13297. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13298. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13299. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13300. {
  13301. BootNotificationInterval = 0;
  13302. if((intervalInt == 0) || (intervalInt >= 10))
  13303. {
  13304. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13305. HeartBeatWaitTime = intervalInt;
  13306. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13307. }
  13308. server_sign = TRUE;
  13309. server_pending =FALSE;
  13310. }
  13311. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13312. {
  13313. server_pending = TRUE;
  13314. }
  13315. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13316. srand(time(NULL));
  13317. refreshStartTimer(&clientTime.Heartbeat);
  13318. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13319. SetOcppConnStatus(TRUE);
  13320. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13321. }
  13322. void handleDataTransferResponse(char *payload, int gun_index)
  13323. {
  13324. json_object *DataTransfer = json_tokener_parse(payload);
  13325. if(!is_error(DataTransfer))
  13326. {
  13327. // Required data
  13328. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13329. // Optional data
  13330. if(json_object_object_get(DataTransfer, "data") != NULL)
  13331. {
  13332. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13333. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13334. if(!is_error(Data))
  13335. {
  13336. if(json_object_object_get(Data, "msgId") != NULL)
  13337. {
  13338. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13339. {
  13340. 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")));
  13341. }
  13342. }
  13343. }
  13344. json_object_put(Data);
  13345. }
  13346. }
  13347. json_object_put(DataTransfer);
  13348. }
  13349. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13350. {
  13351. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13352. //struct json_object *obj;
  13353. // obj = json_tokener_parse(payload);
  13354. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13355. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13356. //No fields are defined.
  13357. }
  13358. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13359. {
  13360. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13361. //struct json_object *obj;
  13362. // obj = json_tokener_parse(payload);
  13363. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13364. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13365. //No fields are defined.
  13366. }
  13367. void handleHeartbeatResponse(char *payload, int gun_index)
  13368. {
  13369. mtrace();
  13370. DEBUG_INFO("handleHeartbeatResponse...\n");
  13371. json_object *Heartbeat;
  13372. Heartbeat = json_tokener_parse(payload);
  13373. if(!is_error(Heartbeat))
  13374. {
  13375. // Required data
  13376. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13377. }
  13378. json_object_put(Heartbeat);
  13379. if(FirstHeartBeat == 0)
  13380. {
  13381. FirstHeartBeat = 1;
  13382. DEBUG_INFO("FirstHeartBeat \n");
  13383. }
  13384. HeartBeatWithNOResponse = 0;
  13385. refreshStartTimer(&clientTime.Heartbeat);
  13386. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13387. }
  13388. void handleMeterValuesResponse(char *payload, int gun_index)
  13389. {
  13390. mtrace();
  13391. DEBUG_INFO("handleMeterValuesResponse...\n");
  13392. isQueueSendable = 1;
  13393. }
  13394. void handleStartTransactionResponse(char *payload, int gun_index)
  13395. {
  13396. mtrace();
  13397. //int transactionIdInt = 0;
  13398. FILE *outfile;
  13399. char data[100]={0};
  13400. DEBUG_INFO("handleStartTransactionResponse...\n");
  13401. json_object *StartTransaction;
  13402. StartTransaction = json_tokener_parse(payload);
  13403. if(!is_error(StartTransaction))
  13404. {
  13405. // Required data
  13406. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13407. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13408. // Optional data
  13409. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13410. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13411. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13412. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13413. }
  13414. json_object_put(StartTransaction);
  13415. isQueueSendable = 1;
  13416. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13417. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13418. //-----------Start : write to the Queue TransactionId file -----------------//
  13419. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13420. {}
  13421. else
  13422. {
  13423. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13424. if(log == NULL)
  13425. {
  13426. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13427. return ;
  13428. }
  13429. else
  13430. {
  13431. fclose(log);
  13432. }
  13433. }
  13434. // open file for writing
  13435. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13436. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13437. {
  13438. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13439. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13440. fputs(data, outfile);
  13441. fclose (outfile);
  13442. }
  13443. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13444. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13445. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13446. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13447. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13448. }
  13449. void handleStatusNotificationResponse(char *payload, int gun_index)
  13450. {
  13451. mtrace();
  13452. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13453. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13454. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13455. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13456. }
  13457. void handleStopTransactionnResponse(char *payload, int gun_index)
  13458. {
  13459. mtrace();
  13460. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13461. json_object *StopTransaction;
  13462. StopTransaction = json_tokener_parse(payload);
  13463. if(!is_error(StopTransaction))
  13464. {
  13465. // Optional data
  13466. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13467. {
  13468. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13469. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13470. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13471. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13472. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13473. }
  13474. }
  13475. json_object_put(StopTransaction);
  13476. isQueueSendable = 1;
  13477. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13478. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13479. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13480. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13481. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13482. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13483. }
  13484. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13485. {
  13486. mtrace();
  13487. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13488. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13489. }
  13490. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13491. {
  13492. mtrace();
  13493. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13494. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13495. }
  13496. void handleSignCertificateResponse(char *payload, int gun_index)
  13497. {
  13498. mtrace();
  13499. DEBUG_INFO("handleSignCertificateResponse...\n");
  13500. json_object *SignCertificate;
  13501. SignCertificate = json_tokener_parse(payload);
  13502. if(!is_error(SignCertificate))
  13503. {
  13504. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13505. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13506. }
  13507. json_object_put(SignCertificate);
  13508. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13509. }
  13510. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13511. {
  13512. mtrace();
  13513. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13514. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13515. }
  13516. //==========================================
  13517. // Handle Error routine
  13518. //==========================================
  13519. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13520. {
  13521. mtrace();
  13522. #ifdef SystemLogMessage
  13523. DEBUG_INFO("errorCode: %s\n", errorCode);
  13524. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13525. DEBUG_INFO("errorDetails: %s\n", payload);
  13526. #endif
  13527. }
  13528. //===============================================
  13529. // Common routine
  13530. //===============================================
  13531. int initialConfigurationTable(void)
  13532. {
  13533. //clock_t start_t, end_t, total_t;
  13534. FILE *fp;
  13535. FILE *outfile;
  13536. char str[512]={0};
  13537. char sstr[256]={0};
  13538. int c = 0;
  13539. char *loc;
  13540. int confVersion = 13;
  13541. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13542. //start_t = clock();
  13543. //printf("Starting of the program, start_t = %ld\n", start_t);
  13544. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13545. // Check configuration file size is correct
  13546. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13547. {
  13548. struct stat st;
  13549. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13550. if(st.st_size < 3100)
  13551. {
  13552. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13553. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13554. }
  13555. }
  13556. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13557. {
  13558. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13559. if(outfile == NULL)
  13560. {
  13561. DEBUG_INFO("Error opening file\n");
  13562. return FALSE;
  13563. }
  13564. /*Core Profile*/
  13565. //AllowOfflineTxForUnknownId
  13566. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13567. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13568. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13570. //AuthorizationCacheEnabled
  13571. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13575. //AuthorizeRemoteTxRequests
  13576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13580. //BlinkRepeat
  13581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13585. //ClockAlignedDataInterval
  13586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13590. //ConnectionTimeOut
  13591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13595. //GetConfigurationMaxKeys
  13596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13600. // HeartbeatInterval
  13601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13605. // LightIntensity
  13606. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13610. // LocalAuthorizeOffline
  13611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13615. // LocalPreAuthorize
  13616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13617. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13620. // MaxEnergyOnInvalidId
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13625. // MeterValuesAlignedData
  13626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13629. 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" );
  13630. else
  13631. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13633. // MeterValuesAlignedDataMaxLength
  13634. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13638. else
  13639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13641. // MeterValuesSampledData
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13645. 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" );
  13646. else
  13647. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13649. // MeterValuesSampledDataMaxLength
  13650. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13653. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13654. else
  13655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13657. // MeterValueSampleInterval
  13658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13662. // MinimumStatusDuration
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13666. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13668. // NumberOfConnectors
  13669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13672. {
  13673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13674. }
  13675. else
  13676. {
  13677. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13678. }
  13679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13680. // ResetRetries
  13681. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13682. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13683. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13685. // ConnectorPhaseRotation
  13686. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13690. // ConnectorPhaseRotationMaxLength
  13691. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13692. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13695. // StopTransactionOnEVSideDisconnect
  13696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13697. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13700. // StopTransactionOnInvalidId
  13701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13705. // StopTxnAlignedData
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13710. // StopTxnAlignedDataMaxLength
  13711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13713. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13715. // StopTxnSampledData
  13716. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13720. else
  13721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13723. // StopTxnSampledDataMaxLength
  13724. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13725. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13727. {
  13728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13729. }
  13730. else
  13731. {
  13732. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13733. }
  13734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13735. // SupportedFeatureProfiles
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13740. // SupportedFeatureProfilesMaxLength
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13745. // TransactionMessageAttempts
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13749. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13751. // TransactionMessageRetryInterval
  13752. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13755. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13757. // UnlockConnectorOnEVSideDisconnect
  13758. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13760. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13762. // WebSocketPingInterval
  13763. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13765. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13767. // QueueOffLineMeterValues
  13768. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13772. // AuthorizationKey
  13773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13774. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13777. // SecurityProfile
  13778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13780. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13782. // DefaultPrice
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13787. // CustomDisplayCostAndPrice
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13792. // CustomIdleFeeAfterStop
  13793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13797. // SystemUptimeSec
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13802. // FreeVend
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13807. // FreeVendIdtag
  13808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13812. // OcppServer
  13813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13815. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13817. // MaintainServer
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13820. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13822. // StatusNotificationPeriodically
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13827. // StatusNotificationInterval
  13828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13832. // Configuration Version
  13833. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13835. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13837. //* Local Auth List Management Profile*/
  13838. #if 0
  13839. //For OCTT Test Case
  13840. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13842. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13843. #endif
  13844. #if 1
  13845. //LocalAuthListEnabled
  13846. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13850. #endif
  13851. //LocalAuthListMaxLength
  13852. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13856. //SendLocalListMaxLength
  13857. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13861. //ReserveConnectorZeroSupported
  13862. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13863. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13866. //* Smart Charging Profile */
  13867. //ChargeProfileMaxStackLevel
  13868. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13872. // ChargingScheduleAllowedChargingRateUnit
  13873. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13877. // ChargingScheduleMaxPeriods
  13878. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13882. // ConnectorSwitch3to1PhaseSupported
  13883. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13887. // MaxChargingProfilesInstalled
  13888. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13892. fclose(outfile);
  13893. }
  13894. else
  13895. {
  13896. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13897. char keystr[60]={0};
  13898. char readonlystr[10]={0};
  13899. char valuestr[256]={0};
  13900. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13901. if(fp == NULL) {
  13902. DEBUG_INFO("Error opening file");
  13903. return FALSE;
  13904. }
  13905. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13906. {
  13907. //DEBUG_INFO("Get Configuration \n");
  13908. if(strlen(str) > 0)
  13909. {
  13910. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13911. //*************************key*********************************/
  13912. if(strstr(str, "key") != NULL)
  13913. {
  13914. loc = strstr(str, "key");
  13915. c = 0;
  13916. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13917. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13918. {
  13919. sstr[c] = loc[strlen("key")+3+c];
  13920. c++;
  13921. }
  13922. sstr[c] = '\0';
  13923. strcpy(keystr,sstr);
  13924. }
  13925. //*************************readonly*********************************/
  13926. if(strstr(str, "readonly") != NULL)
  13927. {
  13928. loc = strstr(str, "readonly");
  13929. c = 0;
  13930. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13931. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13932. {
  13933. sstr[c] = loc[strlen("readonly")+2+c];
  13934. c++;
  13935. }
  13936. sstr[c] = '\0';
  13937. strcpy(readonlystr,sstr);
  13938. }
  13939. //*************************value*********************************/
  13940. if(strstr(str, "value") != NULL)
  13941. {
  13942. loc = strstr(str, "value");
  13943. c = 0;
  13944. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13945. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13946. {
  13947. sstr[c] = loc[strlen("value")+3+c];
  13948. c++;
  13949. }
  13950. sstr[c] = '\0';
  13951. strcpy(valuestr,sstr);
  13952. }
  13953. // DEBUG_INFO("keystr=%s\n",keystr);
  13954. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13955. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13956. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13957. {
  13958. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13959. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13960. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13961. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13962. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13963. }
  13964. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13965. {
  13966. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13967. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13968. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13969. }
  13970. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13971. {
  13972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13973. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13974. }
  13975. if(strcmp(keystr, "BlinkRepeat") == 0)
  13976. {
  13977. //Charger.BlinkRepeat = Integer.parseInt(value);
  13978. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13979. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13980. }
  13981. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13982. {
  13983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13984. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13985. }
  13986. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13987. {
  13988. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13989. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13990. }
  13991. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13992. {
  13993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13994. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13995. }
  13996. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13997. {
  13998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13999. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14000. HeartBeatWaitTime = atoi(valuestr);
  14001. }
  14002. if(strcmp(keystr, "LightIntensity") == 0)
  14003. {
  14004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14005. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14006. }
  14007. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14008. {
  14009. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14011. }
  14012. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14013. {
  14014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14016. }
  14017. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14018. {
  14019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14020. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14021. }
  14022. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14023. {
  14024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14025. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14026. }
  14027. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14028. {
  14029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14031. }
  14032. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14033. {
  14034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14035. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14036. }
  14037. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14038. {
  14039. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14040. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14041. }
  14042. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14043. {
  14044. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14045. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14046. }
  14047. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14048. {
  14049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14051. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14052. }
  14053. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14054. {
  14055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14056. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14057. }
  14058. if(strcmp(keystr, "ResetRetries") == 0)
  14059. {
  14060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14062. }
  14063. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14064. {
  14065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14066. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14067. }
  14068. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14069. {
  14070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14071. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14072. }
  14073. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14074. {
  14075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14076. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14077. }
  14078. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14079. {
  14080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14082. }
  14083. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14084. {
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14087. }
  14088. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14089. {
  14090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14091. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14092. }
  14093. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14094. {
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14097. }
  14098. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14099. {
  14100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14102. }
  14103. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14104. {
  14105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14107. }
  14108. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14109. {
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14112. }
  14113. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14114. {
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14117. TransactionMessageAttemptsValue = atoi(valuestr);
  14118. }
  14119. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14120. {
  14121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14122. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14123. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14124. }
  14125. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14126. {
  14127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14128. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14129. }
  14130. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14131. {
  14132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14133. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14134. }
  14135. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14136. {
  14137. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14138. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14139. }
  14140. if(strcmp(keystr, "AuthorizationKey") == 0)
  14141. {
  14142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14143. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14144. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14145. }
  14146. if(strcmp(keystr, "SecurityProfile") == 0)
  14147. {
  14148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14149. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14150. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14151. }
  14152. if(strcmp(keystr, "DefaultPrice") == 0)
  14153. {
  14154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14156. }
  14157. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14158. {
  14159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14161. }
  14162. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14163. {
  14164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14165. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14166. }
  14167. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14168. {
  14169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14170. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14171. }
  14172. if(strcmp(keystr, "FreeVend") == 0)
  14173. {
  14174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14176. }
  14177. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14178. {
  14179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14181. }
  14182. if(strcmp(keystr, "OcppServer") == 0)
  14183. {
  14184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14185. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14186. }
  14187. if(strcmp(keystr, "MaintainServer") == 0)
  14188. {
  14189. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14190. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14191. }
  14192. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14193. {
  14194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14195. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14196. }
  14197. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14198. {
  14199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14201. }
  14202. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14203. {
  14204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14206. }
  14207. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14208. {
  14209. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14210. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14211. }
  14212. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14213. {
  14214. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14215. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14216. }
  14217. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14218. {
  14219. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14220. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14221. }
  14222. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14223. {
  14224. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14226. }
  14227. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14228. {
  14229. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14231. }
  14232. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14233. {
  14234. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14236. }
  14237. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14238. {
  14239. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14241. }
  14242. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14243. {
  14244. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14246. }
  14247. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14248. {
  14249. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14250. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14251. }
  14252. }
  14253. }
  14254. fclose(fp);
  14255. }
  14256. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14257. {
  14258. return PASS;
  14259. }
  14260. else
  14261. {
  14262. return FAIL;
  14263. }
  14264. }
  14265. void StoreConfigurationTable(void)
  14266. {
  14267. FILE *outfile;
  14268. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14269. if(outfile == NULL)
  14270. {
  14271. DEBUG_INFO("Error opening file");
  14272. return ;
  14273. }
  14274. /*Core Profile*/
  14275. //AllowOfflineTxForUnknownId
  14276. /*
  14277. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14278. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14280. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14281. */
  14282. //DEBUG_INFO("data=%s\n",data);
  14283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14284. //AuthorizationCacheEnabled
  14285. /*
  14286. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14289. */
  14290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14291. //AuthorizeRemoteTxRequests
  14292. /*
  14293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14296. */
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14298. //BlinkRepeat
  14299. /*
  14300. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14303. */
  14304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14305. //ClockAlignedDataInterval
  14306. /*
  14307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14310. */
  14311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14312. //ConnectionTimeOut
  14313. /*
  14314. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14315. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14317. */
  14318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14319. //GetConfigurationMaxKeys
  14320. /*
  14321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14324. */
  14325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14326. // HeartbeatInterval
  14327. /*
  14328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14329. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14331. */
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14333. // LightIntensity
  14334. /*
  14335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14338. */
  14339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14340. // LocalAuthorizeOffline
  14341. /*
  14342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14344. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14345. */
  14346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14347. // LocalPreAuthorize
  14348. /*
  14349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14352. */
  14353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14354. // MaxEnergyOnInvalidId
  14355. /*
  14356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14359. */
  14360. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14362. // MeterValuesAlignedData
  14363. /*
  14364. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14365. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14367. */
  14368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14369. // MeterValuesAlignedDataMaxLength
  14370. /*
  14371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14374. */
  14375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14376. // MeterValuesSampledData
  14377. /*
  14378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14381. */
  14382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14383. // MeterValuesSampledDataMaxLength
  14384. /*
  14385. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14388. */
  14389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14390. // MeterValueSampleInterval
  14391. /*
  14392. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14395. */
  14396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14397. // MinimumStatusDuration
  14398. /*
  14399. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14402. */
  14403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14404. // NumberOfConnectors
  14405. /*
  14406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14409. {
  14410. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14411. }
  14412. else
  14413. {
  14414. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14415. }
  14416. */
  14417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14418. // ResetRetries
  14419. /*
  14420. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14423. */
  14424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14425. // ConnectorPhaseRotation
  14426. /*
  14427. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14429. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14430. */
  14431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14432. // ConnectorPhaseRotationMaxLength
  14433. /*
  14434. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14435. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14437. */
  14438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14439. // StopTransactionOnEVSideDisconnect
  14440. /*
  14441. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14444. */
  14445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14446. // StopTransactionOnInvalidId
  14447. /*
  14448. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14449. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14450. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14451. */
  14452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14453. // StopTxnAlignedData
  14454. /*
  14455. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14458. */
  14459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14460. // StopTxnAlignedDataMaxLength
  14461. /*
  14462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14464. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14465. */
  14466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14467. // StopTxnSampledData
  14468. /*
  14469. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14470. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14472. */
  14473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14474. // StopTxnSampledDataMaxLength
  14475. /*
  14476. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14478. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14479. */
  14480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14481. // SupportedFeatureProfiles
  14482. /*
  14483. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14484. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14485. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14486. */
  14487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14488. // SupportedFeatureProfilesMaxLength
  14489. /*
  14490. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14491. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14492. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14493. */
  14494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14495. // TransactionMessageAttempts
  14496. /*
  14497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14499. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14500. */
  14501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14502. // TransactionMessageRetryInterval
  14503. /*
  14504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14506. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14507. */
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14509. // UnlockConnectorOnEVSideDisconnect
  14510. /*
  14511. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14513. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14514. */
  14515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14516. // WebSocketPingInterval
  14517. /*
  14518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14521. */
  14522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14523. // QueueOffLineMeterValues
  14524. /*
  14525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14526. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14528. */
  14529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14530. // AuthorizationKey
  14531. /*
  14532. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14535. */
  14536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14537. // SecurityProfile
  14538. /*
  14539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14540. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14541. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14542. */
  14543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14544. // DefaultPrice
  14545. /*
  14546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14549. */
  14550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14551. // CustomDisplayCostAndPrice
  14552. /*
  14553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14555. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14556. */
  14557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14558. // CustomIdleFeeAfterStop
  14559. /*
  14560. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14561. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14562. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14563. */
  14564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14565. // SystemUptimeSec
  14566. /*
  14567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14568. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14570. */
  14571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14572. // FreeVend
  14573. /*
  14574. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14577. */
  14578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14579. // FreeVendIdtag
  14580. /*
  14581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14584. */
  14585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14586. // OcppServer
  14587. /*
  14588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14591. */
  14592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14593. // MaintainServer
  14594. /*
  14595. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14598. */
  14599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14600. // StatusNotificationPeriodically
  14601. /*
  14602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14604. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14605. */
  14606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14607. // StatusNotificationInterval
  14608. /*
  14609. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14610. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14611. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14612. */
  14613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14614. // ConfigurationVersion
  14615. /*
  14616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14617. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14619. */
  14620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14621. //* Local Auth List Management Profile*/
  14622. //LocalAuthListEnabled
  14623. /*
  14624. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14626. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14627. */
  14628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14629. //LocalAuthListMaxLength
  14630. /*
  14631. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14632. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14634. */
  14635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14636. //SendLocalListMaxLength
  14637. /*
  14638. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14641. */
  14642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14643. //ReserveConnectorZeroSupported
  14644. /*
  14645. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14646. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14647. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14648. */
  14649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14650. //* Smart Charging Profile */
  14651. //ChargeProfileMaxStackLevel
  14652. /*
  14653. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14656. */
  14657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14658. // ChargingScheduleAllowedChargingRateUnit
  14659. /*
  14660. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14663. */
  14664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14665. // ChargingScheduleMaxPeriods
  14666. /*
  14667. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14670. */
  14671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14672. // ConnectorSwitch3to1PhaseSupported
  14673. /*
  14674. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14677. */
  14678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14679. // MaxChargingProfilesInstalled
  14680. /*
  14681. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14682. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14683. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14684. */
  14685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14686. fclose(outfile);
  14687. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14688. }
  14689. void getKeyValue(char *keyReq)
  14690. {
  14691. int isEmpty = FALSE;
  14692. int isKnowKey = FALSE;
  14693. DEBUG_INFO("keyReq = %s\n", keyReq);
  14694. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14695. isEmpty = TRUE;
  14696. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14697. {
  14698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14701. {
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14703. }
  14704. else
  14705. {
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14707. }
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14709. isKnowKey = TRUE;
  14710. }
  14711. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14712. {
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14716. {
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14718. }
  14719. else
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14722. }
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14724. isKnowKey = TRUE;
  14725. }
  14726. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14727. {
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14730. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14731. {
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14733. }
  14734. else
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14737. }
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14739. isKnowKey = TRUE;
  14740. }
  14741. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14742. {
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14746. {
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14748. }
  14749. else
  14750. {
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14752. }
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14754. isKnowKey = TRUE;
  14755. }
  14756. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14757. {
  14758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14761. {
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14763. }
  14764. else
  14765. {
  14766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14767. }
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14769. isKnowKey = TRUE;
  14770. }
  14771. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14772. {
  14773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14775. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14776. {
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14778. }
  14779. else
  14780. {
  14781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14782. }
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14784. isKnowKey = TRUE;
  14785. }
  14786. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14787. {
  14788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14790. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14791. {
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14793. }
  14794. else
  14795. {
  14796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14797. }
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14799. isKnowKey = TRUE;
  14800. }
  14801. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14802. {
  14803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14805. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14806. {
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14808. }
  14809. else
  14810. {
  14811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14812. }
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14814. isKnowKey = TRUE;
  14815. }
  14816. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14817. {
  14818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14820. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14821. {
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14823. }
  14824. else
  14825. {
  14826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14827. }
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14829. isKnowKey = TRUE;
  14830. }
  14831. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14832. {
  14833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14835. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14836. {
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14838. }
  14839. else
  14840. {
  14841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14842. }
  14843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14844. isKnowKey = TRUE;
  14845. }
  14846. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14847. {
  14848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14850. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14851. {
  14852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14853. }
  14854. else
  14855. {
  14856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14857. }
  14858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14859. isKnowKey = TRUE;
  14860. }
  14861. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14862. {
  14863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14865. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14866. {
  14867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14868. }
  14869. else
  14870. {
  14871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14872. }
  14873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14874. isKnowKey = TRUE;
  14875. }
  14876. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14877. {
  14878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14880. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14881. {
  14882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14883. }
  14884. else
  14885. {
  14886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14887. }
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14889. isKnowKey = TRUE;
  14890. }
  14891. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14892. {
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14895. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14896. {
  14897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14898. }
  14899. else
  14900. {
  14901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14902. }
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14904. isKnowKey = TRUE;
  14905. }
  14906. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14907. {
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14910. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14911. {
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14913. }
  14914. else
  14915. {
  14916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14917. }
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14919. isKnowKey = TRUE;
  14920. }
  14921. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14922. {
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14925. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14926. {
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14928. }
  14929. else
  14930. {
  14931. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14932. }
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14934. isKnowKey = TRUE;
  14935. }
  14936. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14937. {
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14939. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14940. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14941. {
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14943. }
  14944. else
  14945. {
  14946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14947. }
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14949. isKnowKey = TRUE;
  14950. }
  14951. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14952. {
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14955. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14956. {
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14958. }
  14959. else
  14960. {
  14961. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14962. }
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14964. isKnowKey = TRUE;
  14965. }
  14966. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14967. {
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14970. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14971. {
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14973. }
  14974. else
  14975. {
  14976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14977. }
  14978. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14980. isKnowKey = TRUE;
  14981. }
  14982. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14983. {
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14986. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14987. {
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14989. }
  14990. else
  14991. {
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14993. }
  14994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14995. isKnowKey = TRUE;
  14996. }
  14997. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14998. {
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15001. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15002. {
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15004. }
  15005. else
  15006. {
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15008. }
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15010. isKnowKey = TRUE;
  15011. }
  15012. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15013. {
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15016. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15017. {
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15019. }
  15020. else
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15023. }
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15025. isKnowKey = TRUE;
  15026. }
  15027. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15028. {
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15031. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15032. {
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15034. }
  15035. else
  15036. {
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15038. }
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15040. isKnowKey = TRUE;
  15041. }
  15042. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15043. {
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15046. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15049. }
  15050. else
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15053. }
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15055. isKnowKey = TRUE;
  15056. }
  15057. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15058. {
  15059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15061. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15062. {
  15063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15064. }
  15065. else
  15066. {
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15068. }
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15070. isKnowKey = TRUE;
  15071. }
  15072. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15073. {
  15074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15076. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15077. {
  15078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15079. }
  15080. else
  15081. {
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15083. }
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15085. isKnowKey = TRUE;
  15086. }
  15087. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15088. {
  15089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15091. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15092. {
  15093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15094. }
  15095. else
  15096. {
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15098. }
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15100. isKnowKey = TRUE;
  15101. }
  15102. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15103. {
  15104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15106. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15107. {
  15108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15109. }
  15110. else
  15111. {
  15112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15113. }
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15115. isKnowKey = TRUE;
  15116. }
  15117. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15118. {
  15119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15121. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15122. {
  15123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15124. }
  15125. else
  15126. {
  15127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15128. }
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15130. isKnowKey = TRUE;
  15131. }
  15132. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15133. {
  15134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15136. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15137. {
  15138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15139. }
  15140. else
  15141. {
  15142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15143. }
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15145. isKnowKey = TRUE;
  15146. }
  15147. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15148. {
  15149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15151. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15152. {
  15153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15154. }
  15155. else
  15156. {
  15157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15158. }
  15159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15160. isKnowKey = TRUE;
  15161. }
  15162. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15163. {
  15164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15167. {
  15168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15169. }
  15170. else
  15171. {
  15172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15173. }
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15175. isKnowKey = TRUE;
  15176. }
  15177. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15178. {
  15179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15181. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15182. {
  15183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15184. }
  15185. else
  15186. {
  15187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15188. }
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15190. isKnowKey = TRUE;
  15191. }
  15192. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15193. {
  15194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15196. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15197. {
  15198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15199. }
  15200. else
  15201. {
  15202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15203. }
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15205. isKnowKey = TRUE;
  15206. }
  15207. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15208. {
  15209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15211. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15212. {
  15213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15214. }
  15215. else
  15216. {
  15217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15218. }
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15220. isKnowKey = TRUE;
  15221. }
  15222. /*
  15223. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15224. {
  15225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15227. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15228. {
  15229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15230. }
  15231. else
  15232. {
  15233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15234. }
  15235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15236. isKnowKey = TRUE;
  15237. }*/
  15238. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15239. {
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15242. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15243. {
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15245. }
  15246. else
  15247. {
  15248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15249. }
  15250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15251. isKnowKey = TRUE;
  15252. }
  15253. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15254. {
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15257. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15258. {
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15260. }
  15261. else
  15262. {
  15263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15264. }
  15265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15266. isKnowKey = TRUE;
  15267. }
  15268. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15269. {
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15272. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15273. {
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15275. }
  15276. else
  15277. {
  15278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15279. }
  15280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15281. isKnowKey = TRUE;
  15282. }
  15283. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15284. {
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15287. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15288. {
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15290. }
  15291. else
  15292. {
  15293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15294. }
  15295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15296. isKnowKey = TRUE;
  15297. }
  15298. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15299. {
  15300. struct sysinfo s_info;
  15301. int error = sysinfo(&s_info);
  15302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15305. {
  15306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15307. }
  15308. else
  15309. {
  15310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15311. }
  15312. if(error != 0)
  15313. {
  15314. DEBUG_WARN("System uptime get error: %d\n", error);
  15315. }
  15316. else
  15317. {
  15318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15319. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15320. }
  15321. isKnowKey = TRUE;
  15322. }
  15323. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15324. {
  15325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15327. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15328. {
  15329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15330. }
  15331. else
  15332. {
  15333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15334. }
  15335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15336. isKnowKey = TRUE;
  15337. }
  15338. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15339. {
  15340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15343. {
  15344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15345. }
  15346. else
  15347. {
  15348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15349. }
  15350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15351. isKnowKey = TRUE;
  15352. }
  15353. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15354. {
  15355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15357. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15358. {
  15359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15360. }
  15361. else
  15362. {
  15363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15364. }
  15365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15366. isKnowKey = TRUE;
  15367. }
  15368. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15369. {
  15370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15372. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15373. {
  15374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15375. }
  15376. else
  15377. {
  15378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15379. }
  15380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15381. isKnowKey = TRUE;
  15382. }
  15383. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15384. {
  15385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15387. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15388. {
  15389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15390. }
  15391. else
  15392. {
  15393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15394. }
  15395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15396. isKnowKey = TRUE;
  15397. }
  15398. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15399. {
  15400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15402. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15403. {
  15404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15405. }
  15406. else
  15407. {
  15408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15409. }
  15410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15411. isKnowKey = TRUE;
  15412. }
  15413. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15414. {
  15415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15418. {
  15419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15420. }
  15421. else
  15422. {
  15423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15424. }
  15425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15426. isKnowKey = TRUE;
  15427. }
  15428. #if 1
  15429. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15430. {
  15431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15433. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15434. {
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15436. }
  15437. else
  15438. {
  15439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15440. }
  15441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15442. isKnowKey = TRUE;
  15443. }
  15444. #endif
  15445. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15446. {
  15447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15449. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15450. {
  15451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15452. }
  15453. else
  15454. {
  15455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15456. }
  15457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15458. isKnowKey = TRUE;
  15459. }
  15460. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15461. {
  15462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15464. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15465. {
  15466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15467. }
  15468. else
  15469. {
  15470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15471. }
  15472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15473. isKnowKey = TRUE;
  15474. }
  15475. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15476. {
  15477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15479. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15480. {
  15481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15482. }
  15483. else
  15484. {
  15485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15486. }
  15487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15488. isKnowKey = TRUE;
  15489. }
  15490. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15491. {
  15492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15494. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15495. {
  15496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15497. }
  15498. else
  15499. {
  15500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15501. }
  15502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15503. isKnowKey = TRUE;
  15504. }
  15505. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15506. {
  15507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15509. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15510. {
  15511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15512. }
  15513. else
  15514. {
  15515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15516. }
  15517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15518. isKnowKey = TRUE;
  15519. }
  15520. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15521. {
  15522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15524. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15525. {
  15526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15527. }
  15528. else
  15529. {
  15530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15531. }
  15532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15533. isKnowKey = TRUE;
  15534. }
  15535. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15536. {
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15539. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15540. {
  15541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15542. }
  15543. else
  15544. {
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15546. }
  15547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15548. isKnowKey = TRUE;
  15549. }
  15550. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15554. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15557. }
  15558. else
  15559. {
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15561. }
  15562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15563. isKnowKey = TRUE;
  15564. }
  15565. //=========================================================
  15566. if(!isEmpty && !isKnowKey)
  15567. {
  15568. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15569. strcpy(unknownkey[UnknownKeynum], keyReq);
  15570. UnknownKeynum = UnknownKeynum + 1;
  15571. }
  15572. }
  15573. void processUnkownKey(void)
  15574. {
  15575. DEBUG_INFO("processUnkownKey...\n");
  15576. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15577. for(int index=0; index < UnknownKeynum; index++)
  15578. {
  15579. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15580. {
  15581. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15582. }
  15583. }
  15584. }
  15585. int setKeyValue(char *key, char *value)
  15586. {
  15587. int isSuccess = NotSupported;
  15588. int check_ascii=0;
  15589. char str[501]={0};
  15590. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15591. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15592. {
  15593. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15594. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15595. {
  15596. strcpy(str, (const char*)value);
  15597. for(int i = 0; str[i]; i++){
  15598. str[i] = tolower(str[i]);
  15599. }
  15600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15601. isSuccess = ConfigurationStatus_Accepted;
  15602. }
  15603. else
  15604. {
  15605. isSuccess = ConfigurationStatus_Rejected;
  15606. }
  15607. }
  15608. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15609. {
  15610. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15611. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15612. {
  15613. strcpy(str, (const char*)value);
  15614. for(int i = 0; str[i]; i++){
  15615. str[i] = tolower(str[i]);
  15616. }
  15617. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15618. isSuccess = ConfigurationStatus_Accepted;
  15619. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15620. }
  15621. else
  15622. {
  15623. isSuccess = ConfigurationStatus_Rejected;
  15624. }
  15625. }
  15626. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15627. {
  15628. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15629. {
  15630. strcpy(str, (const char*)value);
  15631. for(int i = 0; str[i]; i++)
  15632. {
  15633. str[i] = tolower(str[i]);
  15634. }
  15635. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15636. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15637. isSuccess = ConfigurationStatus_Accepted;
  15638. }
  15639. else
  15640. {
  15641. isSuccess = ConfigurationStatus_Rejected;
  15642. }
  15643. }
  15644. if(strcmp(key, "BlinkRepeat") == 0)
  15645. {
  15646. //Charger.BlinkRepeat = Integer.parseInt(value);
  15647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15648. {
  15649. check_ascii = value[0];
  15650. if( (check_ascii < 48) || (check_ascii > 57) )
  15651. {
  15652. isSuccess = ConfigurationStatus_Rejected;
  15653. }
  15654. else
  15655. {
  15656. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15657. isSuccess = ConfigurationStatus_Accepted;
  15658. }
  15659. }
  15660. else
  15661. {
  15662. isSuccess = ConfigurationStatus_Rejected;
  15663. }
  15664. }
  15665. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15666. {
  15667. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15668. {
  15669. check_ascii = value[0];
  15670. if( (check_ascii < 48) || (check_ascii > 57) )
  15671. {
  15672. isSuccess = ConfigurationStatus_Rejected;
  15673. }
  15674. else
  15675. {
  15676. if((atoi(value) == 0) || (atoi(value) >= 5))
  15677. {
  15678. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15680. isSuccess = ConfigurationStatus_Accepted;
  15681. }
  15682. else
  15683. isSuccess = ConfigurationStatus_Rejected;
  15684. }
  15685. }
  15686. else
  15687. {
  15688. isSuccess = ConfigurationStatus_Rejected;
  15689. }
  15690. }
  15691. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15692. {
  15693. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15694. {
  15695. check_ascii = value[0];
  15696. if( (check_ascii < 48) || (check_ascii > 57) )
  15697. {
  15698. isSuccess = ConfigurationStatus_Rejected;
  15699. }
  15700. else
  15701. {
  15702. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15704. isSuccess = ConfigurationStatus_Accepted;
  15705. }
  15706. }
  15707. else
  15708. {
  15709. isSuccess = ConfigurationStatus_Rejected;
  15710. }
  15711. }
  15712. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15713. {
  15714. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15715. {
  15716. check_ascii = value[0];
  15717. if( (check_ascii < 48) || (check_ascii > 57) )
  15718. {
  15719. isSuccess = ConfigurationStatus_Rejected;
  15720. }
  15721. else
  15722. {
  15723. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15725. isSuccess = ConfigurationStatus_Accepted;
  15726. }
  15727. }
  15728. else
  15729. {
  15730. isSuccess = ConfigurationStatus_Rejected;
  15731. }
  15732. }
  15733. if(strcmp(key, "HeartbeatInterval") == 0)
  15734. {
  15735. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15736. {
  15737. check_ascii = value[0];
  15738. if( (check_ascii < 48) || (check_ascii > 57) )
  15739. {
  15740. isSuccess = ConfigurationStatus_Rejected;
  15741. }
  15742. else
  15743. {
  15744. if((atoi(value) == 0) || (atoi(value) >= 10))
  15745. {
  15746. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15748. HeartBeatWaitTime = atoi(value);
  15749. isSuccess = ConfigurationStatus_Accepted;
  15750. }
  15751. else
  15752. {
  15753. isSuccess = ConfigurationStatus_Rejected;
  15754. }
  15755. }
  15756. }
  15757. else
  15758. {
  15759. isSuccess = ConfigurationStatus_Rejected;
  15760. }
  15761. }
  15762. if(strcmp(key, "LightIntensity") == 0)
  15763. {
  15764. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15765. {
  15766. check_ascii = value[0];
  15767. if( (check_ascii < 48) || (check_ascii > 57) )
  15768. {
  15769. isSuccess = ConfigurationStatus_Rejected;
  15770. }
  15771. else
  15772. {
  15773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15774. isSuccess = ConfigurationStatus_Accepted;
  15775. }
  15776. }
  15777. else
  15778. {
  15779. isSuccess = ConfigurationStatus_Rejected;
  15780. }
  15781. }
  15782. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15783. {
  15784. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15785. {
  15786. strcpy(str, (const char*)value);
  15787. for(int i = 0; str[i]; i++)
  15788. {
  15789. str[i] = tolower(str[i]);
  15790. }
  15791. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15792. isSuccess = ConfigurationStatus_Accepted;
  15793. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15794. }
  15795. else
  15796. {
  15797. isSuccess = ConfigurationStatus_Rejected;
  15798. }
  15799. }
  15800. if(strcmp(key, "LocalPreAuthorize") == 0)
  15801. {
  15802. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15803. {
  15804. strcpy(str, (const char*)value);
  15805. for(int i = 0; str[i]; i++)
  15806. {
  15807. str[i] = tolower(str[i]);
  15808. }
  15809. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15810. isSuccess = ConfigurationStatus_Accepted;
  15811. }
  15812. else
  15813. {
  15814. isSuccess = ConfigurationStatus_Rejected;
  15815. }
  15816. }
  15817. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15818. {
  15819. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15820. {
  15821. check_ascii = value[0];
  15822. if( (check_ascii < 48) || (check_ascii > 57) )
  15823. {
  15824. isSuccess = ConfigurationStatus_Rejected;
  15825. }
  15826. else
  15827. {
  15828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15829. isSuccess = ConfigurationStatus_Accepted;
  15830. }
  15831. }
  15832. else
  15833. {
  15834. isSuccess = ConfigurationStatus_Rejected;
  15835. }
  15836. }
  15837. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15838. {
  15839. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15840. {
  15841. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15842. isSuccess = ConfigurationStatus_Accepted;
  15843. }
  15844. else
  15845. {
  15846. isSuccess = ConfigurationStatus_Rejected;
  15847. }
  15848. }
  15849. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15850. {
  15851. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15852. {
  15853. check_ascii = value[0];
  15854. if( (check_ascii < 48) || (check_ascii > 57) )
  15855. {
  15856. isSuccess = ConfigurationStatus_Rejected;
  15857. }
  15858. else
  15859. {
  15860. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15862. isSuccess = ConfigurationStatus_Accepted;
  15863. }
  15864. }
  15865. else
  15866. {
  15867. isSuccess = ConfigurationStatus_Rejected;
  15868. }
  15869. }
  15870. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15871. {
  15872. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15873. {
  15874. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15875. isSuccess = ConfigurationStatus_Accepted;
  15876. }
  15877. else
  15878. {
  15879. isSuccess = ConfigurationStatus_Rejected;
  15880. }
  15881. }
  15882. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15883. {
  15884. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15885. {
  15886. check_ascii = value[0];
  15887. if( (check_ascii < 48) || (check_ascii > 57) )
  15888. {
  15889. isSuccess = ConfigurationStatus_Rejected;
  15890. }
  15891. else
  15892. {
  15893. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15894. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15895. isSuccess = ConfigurationStatus_Accepted;
  15896. }
  15897. }
  15898. else
  15899. {
  15900. isSuccess = ConfigurationStatus_Rejected;
  15901. }
  15902. }
  15903. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15904. {
  15905. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15906. {
  15907. check_ascii = value[0];
  15908. if( (check_ascii < 48) || (check_ascii > 57) )
  15909. {
  15910. isSuccess = ConfigurationStatus_Rejected;
  15911. }
  15912. else
  15913. {
  15914. if((atoi(value) == 0) || (atoi(value) >= 3))
  15915. {
  15916. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15918. isSuccess = ConfigurationStatus_Accepted;
  15919. }
  15920. else
  15921. {
  15922. isSuccess = ConfigurationStatus_Rejected;
  15923. }
  15924. }
  15925. }
  15926. else
  15927. {
  15928. isSuccess = ConfigurationStatus_Rejected;
  15929. }
  15930. }
  15931. if(strcmp(key, "MinimumStatusDuration") == 0)
  15932. {
  15933. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15934. {
  15935. check_ascii = value[0];
  15936. if( (check_ascii < 48) || (check_ascii > 57) )
  15937. {
  15938. isSuccess = ConfigurationStatus_Rejected;
  15939. }
  15940. else
  15941. {
  15942. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15943. {
  15944. isSuccess = ConfigurationStatus_Rejected;
  15945. }
  15946. else
  15947. {
  15948. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15949. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15950. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15951. isSuccess = ConfigurationStatus_Accepted;
  15952. }
  15953. }
  15954. }
  15955. else
  15956. {
  15957. isSuccess = ConfigurationStatus_Rejected;
  15958. }
  15959. }
  15960. if(strcmp(key, "NumberOfConnectors") == 0)
  15961. {
  15962. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15963. {
  15964. check_ascii = value[0];
  15965. if( (check_ascii < 48) || (check_ascii > 57) )
  15966. {
  15967. isSuccess = ConfigurationStatus_Rejected;
  15968. }
  15969. else
  15970. {
  15971. //Charger.ResetRetries = Integer.parseInt(value);
  15972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15973. isSuccess = ConfigurationStatus_Accepted;
  15974. }
  15975. }
  15976. else
  15977. {
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. if(strcmp(key, "ResetRetries") == 0)
  15982. {
  15983. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15984. {
  15985. check_ascii = value[0];
  15986. if( (check_ascii < 48) || (check_ascii > 57) )
  15987. {
  15988. isSuccess = ConfigurationStatus_Rejected;
  15989. }
  15990. else
  15991. {
  15992. //Charger.ResetRetries = Integer.parseInt(value);
  15993. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15994. isSuccess = ConfigurationStatus_Accepted;
  15995. }
  15996. }
  15997. else
  15998. {
  15999. isSuccess = ConfigurationStatus_Rejected;
  16000. }
  16001. }
  16002. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16003. {
  16004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16005. {
  16006. strcpy(str, (const char*)value);
  16007. for(int i = 0; str[i]; i++)
  16008. {
  16009. str[i] = tolower(str[i]);
  16010. }
  16011. if(strcmp(str, "notapplicable")== 0)
  16012. {
  16013. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16014. isSuccess = ConfigurationStatus_Accepted;
  16015. }
  16016. else if(strcmp(str, "unknown")== 0)
  16017. {
  16018. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16019. isSuccess = ConfigurationStatus_Accepted;
  16020. }
  16021. else if(strcmp(str, "rst")== 0)
  16022. {
  16023. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16024. isSuccess = ConfigurationStatus_Accepted;
  16025. }
  16026. else if(strcmp(str, "rts")== 0)
  16027. {
  16028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16029. isSuccess = ConfigurationStatus_Accepted;
  16030. }
  16031. else if(strcmp(str, "srt")== 0)
  16032. {
  16033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16034. isSuccess = ConfigurationStatus_Accepted;
  16035. }
  16036. else if(strcmp(str, "str")== 0)
  16037. {
  16038. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16039. isSuccess = ConfigurationStatus_Accepted;
  16040. }
  16041. else if(strcmp(str, "trs")== 0)
  16042. {
  16043. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16044. isSuccess = ConfigurationStatus_Accepted;
  16045. }
  16046. else if(strcmp(str, "tsr")== 0)
  16047. {
  16048. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16049. isSuccess = ConfigurationStatus_Accepted;
  16050. }
  16051. else
  16052. {
  16053. isSuccess = ConfigurationStatus_Rejected;
  16054. }
  16055. }
  16056. else
  16057. {
  16058. isSuccess = ConfigurationStatus_Rejected;
  16059. }
  16060. }
  16061. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16062. {
  16063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16064. {
  16065. check_ascii = value[0];
  16066. if( (check_ascii < 48) || (check_ascii > 57) )
  16067. {
  16068. isSuccess = ConfigurationStatus_Rejected;
  16069. }
  16070. else
  16071. {
  16072. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16073. isSuccess = ConfigurationStatus_Accepted;
  16074. }
  16075. }
  16076. else
  16077. {
  16078. isSuccess = ConfigurationStatus_Rejected;
  16079. }
  16080. }
  16081. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16082. {
  16083. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16084. {
  16085. strcpy(str, (const char*)value);
  16086. for(int i = 0; str[i]; i++)
  16087. {
  16088. str[i] = tolower(str[i]);
  16089. }
  16090. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16091. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16092. isSuccess = ConfigurationStatus_Accepted;
  16093. }
  16094. else
  16095. {
  16096. isSuccess = ConfigurationStatus_Rejected;
  16097. }
  16098. }
  16099. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16100. {
  16101. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16102. {
  16103. strcpy(str, (const char*)value);
  16104. for(int i = 0; str[i]; i++)
  16105. {
  16106. str[i] = tolower(str[i]);
  16107. }
  16108. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16109. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16110. isSuccess = ConfigurationStatus_Accepted;
  16111. }
  16112. else
  16113. {
  16114. isSuccess = ConfigurationStatus_Rejected;
  16115. }
  16116. }
  16117. if(strcmp(key, "StopTxnAlignedData") == 0)
  16118. {
  16119. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16120. {
  16121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16122. isSuccess = ConfigurationStatus_Accepted;
  16123. }
  16124. else
  16125. {
  16126. isSuccess = ConfigurationStatus_Rejected;
  16127. }
  16128. }
  16129. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16130. {
  16131. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16132. {
  16133. check_ascii = value[0];
  16134. if( (check_ascii < 48) || (check_ascii > 57) )
  16135. {
  16136. isSuccess = ConfigurationStatus_Rejected;
  16137. }
  16138. else
  16139. {
  16140. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16141. isSuccess = ConfigurationStatus_Accepted;
  16142. }
  16143. }
  16144. else
  16145. {
  16146. isSuccess = ConfigurationStatus_Rejected;
  16147. }
  16148. }
  16149. if(strcmp(key, "StopTxnSampledData") == 0)
  16150. {
  16151. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16152. {
  16153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16154. isSuccess = ConfigurationStatus_Accepted;
  16155. }
  16156. else
  16157. {
  16158. isSuccess = ConfigurationStatus_Rejected;
  16159. }
  16160. }
  16161. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16162. {
  16163. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16164. {
  16165. check_ascii = value[0];
  16166. if( (check_ascii < 48) || (check_ascii > 57) )
  16167. {
  16168. isSuccess = ConfigurationStatus_Rejected;
  16169. }
  16170. else
  16171. {
  16172. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16173. isSuccess = ConfigurationStatus_Accepted;
  16174. }
  16175. }
  16176. else
  16177. {
  16178. isSuccess = ConfigurationStatus_Rejected;
  16179. }
  16180. }
  16181. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16182. {
  16183. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16184. {
  16185. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16186. isSuccess = ConfigurationStatus_Accepted;
  16187. }
  16188. else
  16189. {
  16190. isSuccess = ConfigurationStatus_Rejected;
  16191. }
  16192. }
  16193. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16194. {
  16195. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16196. {
  16197. check_ascii = value[0];
  16198. if( (check_ascii < 48) || (check_ascii > 57) )
  16199. {
  16200. isSuccess = ConfigurationStatus_Rejected;
  16201. }
  16202. else
  16203. {
  16204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16205. isSuccess = ConfigurationStatus_Accepted;
  16206. }
  16207. }
  16208. else
  16209. {
  16210. isSuccess = ConfigurationStatus_Rejected;
  16211. }
  16212. }
  16213. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16214. {
  16215. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16216. {
  16217. check_ascii = value[0];
  16218. if( (check_ascii < 48) || (check_ascii > 57) )
  16219. {
  16220. isSuccess = ConfigurationStatus_Rejected;
  16221. }
  16222. else
  16223. {
  16224. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16225. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16226. TransactionMessageAttemptsValue = atoi(value);
  16227. isSuccess = ConfigurationStatus_Accepted;
  16228. }
  16229. }
  16230. else
  16231. {
  16232. isSuccess = ConfigurationStatus_Rejected;
  16233. }
  16234. }
  16235. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16236. {
  16237. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16238. {
  16239. check_ascii = value[0];
  16240. if( (check_ascii < 48) || (check_ascii > 57) )
  16241. {
  16242. isSuccess = ConfigurationStatus_Rejected;
  16243. }
  16244. else
  16245. {
  16246. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16247. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16248. TransactionMessageRetryIntervalValue = atoi(value);
  16249. isSuccess = ConfigurationStatus_Accepted;
  16250. }
  16251. }
  16252. else
  16253. {
  16254. isSuccess = ConfigurationStatus_Rejected;
  16255. }
  16256. }
  16257. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16258. {
  16259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16260. {
  16261. strcpy(str, (const char*)value);
  16262. for(int i = 0; str[i]; i++)
  16263. {
  16264. str[i] = tolower(str[i]);
  16265. }
  16266. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16268. isSuccess = ConfigurationStatus_Accepted;
  16269. }
  16270. else
  16271. {
  16272. isSuccess = ConfigurationStatus_Rejected;
  16273. }
  16274. }
  16275. if(strcmp(key, "WebSocketPingInterval") == 0)
  16276. {
  16277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].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. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16287. isSuccess = ConfigurationStatus_Accepted;
  16288. if((atoi(value) == 0) || (atoi(value) >= 10))
  16289. {
  16290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16291. isSuccess = ConfigurationStatus_Accepted;
  16292. }
  16293. else
  16294. isSuccess = ConfigurationStatus_Rejected;
  16295. }
  16296. }
  16297. else
  16298. {
  16299. isSuccess = ConfigurationStatus_Rejected;
  16300. }
  16301. }
  16302. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16303. {
  16304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16305. {
  16306. strcpy(str, (const char*)value);
  16307. for(int i = 0; str[i]; i++)
  16308. {
  16309. str[i] = tolower(str[i]);
  16310. }
  16311. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16312. isSuccess = ConfigurationStatus_Accepted;
  16313. }
  16314. else
  16315. {
  16316. isSuccess = ConfigurationStatus_Rejected;
  16317. }
  16318. }
  16319. if(strcmp(key, "AuthorizationKey") == 0)
  16320. {
  16321. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16322. {
  16323. strcpy(str, (const char*)value);
  16324. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16325. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16326. isSuccess = ConfigurationStatus_Accepted;
  16327. }
  16328. else
  16329. {
  16330. isSuccess = ConfigurationStatus_Rejected;
  16331. }
  16332. }
  16333. if(strcmp(key, "SecurityProfile") == 0)
  16334. {
  16335. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16336. {
  16337. check_ascii = value[0];
  16338. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16339. {
  16340. isSuccess = ConfigurationStatus_Rejected;
  16341. }
  16342. else if(check_ascii == 0x33)
  16343. {
  16344. isSuccess = NotSupported;
  16345. }
  16346. else
  16347. {
  16348. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16349. {
  16350. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16351. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16352. isSuccess = ConfigurationStatus_Accepted;
  16353. }
  16354. else
  16355. isSuccess = ConfigurationStatus_Rejected;
  16356. }
  16357. }
  16358. else
  16359. {
  16360. isSuccess = ConfigurationStatus_Rejected;
  16361. }
  16362. }
  16363. if(strcmp(key, "DefaultPrice") == 0)
  16364. {
  16365. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16366. {
  16367. strcpy(str, (const char*)value);
  16368. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16369. isSuccess = ConfigurationStatus_Accepted;
  16370. }
  16371. else
  16372. {
  16373. isSuccess = ConfigurationStatus_Rejected;
  16374. }
  16375. }
  16376. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16377. {
  16378. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16379. {
  16380. strcpy(str, (const char*)value);
  16381. for(int i = 0; str[i]; i++)
  16382. {
  16383. str[i] = tolower(str[i]);
  16384. }
  16385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16386. isSuccess = ConfigurationStatus_Accepted;
  16387. }
  16388. else
  16389. {
  16390. isSuccess = ConfigurationStatus_Rejected;
  16391. }
  16392. }
  16393. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16394. {
  16395. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16396. {
  16397. strcpy(str, (const char*)value);
  16398. for(int i = 0; str[i]; i++)
  16399. {
  16400. str[i] = tolower(str[i]);
  16401. }
  16402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16403. isSuccess = ConfigurationStatus_Accepted;
  16404. }
  16405. else
  16406. {
  16407. isSuccess = ConfigurationStatus_Rejected;
  16408. }
  16409. }
  16410. if(strcmp(key, "SystemUptimeSec") == 0)
  16411. {
  16412. isSuccess = NotSupported;
  16413. }
  16414. if(strcmp(key, "FreeVend") == 0)
  16415. {
  16416. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16417. {
  16418. strcpy(str, (const char*)value);
  16419. for(int i = 0; str[i]; i++)
  16420. {
  16421. str[i] = tolower(str[i]);
  16422. }
  16423. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16424. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16425. isSuccess = ConfigurationStatus_Accepted;
  16426. }
  16427. else
  16428. {
  16429. isSuccess = ConfigurationStatus_Rejected;
  16430. }
  16431. }
  16432. if(strcmp(key, "FreeVendIdtag") == 0)
  16433. {
  16434. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16435. {
  16436. strcpy(str, (const char*)value);
  16437. if(strlen(str) <= 20)
  16438. {
  16439. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16440. isSuccess = ConfigurationStatus_Accepted;
  16441. }
  16442. else
  16443. {
  16444. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16445. isSuccess = ConfigurationStatus_Rejected;
  16446. }
  16447. }
  16448. else
  16449. {
  16450. isSuccess = ConfigurationStatus_Rejected;
  16451. }
  16452. }
  16453. if(strcmp(key, "OcppServer") == 0)
  16454. {
  16455. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16456. {
  16457. strcpy(str, (const char*)value);
  16458. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16459. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16460. isSuccess = ConfigurationStatus_Accepted;
  16461. }
  16462. else
  16463. {
  16464. isSuccess = ConfigurationStatus_Rejected;
  16465. }
  16466. }
  16467. if(strcmp(key, "MaintainServer") == 0)
  16468. {
  16469. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16470. {
  16471. strcpy(str, (const char*)value);
  16472. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16473. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16474. isSuccess = ConfigurationStatus_Accepted;
  16475. }
  16476. else
  16477. {
  16478. isSuccess = ConfigurationStatus_Rejected;
  16479. }
  16480. }
  16481. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16482. {
  16483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16484. {
  16485. strcpy(str, (const char*)value);
  16486. for(int i = 0; str[i]; i++)
  16487. {
  16488. str[i] = tolower(str[i]);
  16489. }
  16490. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16491. isSuccess = ConfigurationStatus_Accepted;
  16492. }
  16493. else
  16494. {
  16495. isSuccess = ConfigurationStatus_Rejected;
  16496. }
  16497. }
  16498. if(strcmp(key, "StatusNotificationInterval") == 0)
  16499. {
  16500. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16501. {
  16502. check_ascii = value[0];
  16503. if( (check_ascii < 48) || (check_ascii > 57) )
  16504. {
  16505. isSuccess = ConfigurationStatus_Rejected;
  16506. }
  16507. else
  16508. {
  16509. if((atoi(value) == 0) || (atoi(value) >= 10))
  16510. {
  16511. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16512. isSuccess = ConfigurationStatus_Accepted;
  16513. }
  16514. else
  16515. isSuccess = ConfigurationStatus_Rejected;
  16516. }
  16517. }
  16518. else
  16519. {
  16520. isSuccess = ConfigurationStatus_Rejected;
  16521. }
  16522. }
  16523. #if 0
  16524. //For OCPP Test Case
  16525. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16526. {
  16527. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].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. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16535. isSuccess = ConfigurationStatus_Accepted;
  16536. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16537. }
  16538. else
  16539. {
  16540. isSuccess = ConfigurationStatus_Rejected;
  16541. }
  16542. }
  16543. #endif
  16544. #if 1
  16545. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16546. {
  16547. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16548. {
  16549. strcpy(str, (const char*)value);
  16550. for(int i = 0; str[i]; i++)
  16551. {
  16552. str[i] = tolower(str[i]);
  16553. }
  16554. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16555. isSuccess = ConfigurationStatus_Accepted;
  16556. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16557. }
  16558. else
  16559. {
  16560. isSuccess = ConfigurationStatus_Rejected;
  16561. }
  16562. }
  16563. #endif
  16564. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16565. {
  16566. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16567. {
  16568. check_ascii = value[0];
  16569. if( (check_ascii < 48) || (check_ascii > 57) )
  16570. {
  16571. isSuccess = ConfigurationStatus_Rejected;
  16572. }
  16573. else
  16574. {
  16575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16576. isSuccess = ConfigurationStatus_Accepted;
  16577. }
  16578. }
  16579. else
  16580. {
  16581. isSuccess = ConfigurationStatus_Rejected;
  16582. }
  16583. }
  16584. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16585. {
  16586. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16587. {
  16588. check_ascii = value[0];
  16589. if( (check_ascii < 48) || (check_ascii > 57) )
  16590. {
  16591. isSuccess = ConfigurationStatus_Rejected;
  16592. }
  16593. else
  16594. {
  16595. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16596. isSuccess = ConfigurationStatus_Accepted;
  16597. }
  16598. }
  16599. else
  16600. {
  16601. isSuccess = ConfigurationStatus_Rejected;
  16602. }
  16603. }
  16604. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16605. {
  16606. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16607. {
  16608. strcpy(str, (const char*)value);
  16609. for(int i = 0; str[i]; i++)
  16610. {
  16611. str[i] = tolower(str[i]);
  16612. }
  16613. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16614. isSuccess = ConfigurationStatus_Accepted;
  16615. }
  16616. else
  16617. {
  16618. isSuccess = ConfigurationStatus_Rejected;
  16619. }
  16620. }
  16621. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16622. {
  16623. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16624. {
  16625. check_ascii = value[0];
  16626. if( (check_ascii < 48) || (check_ascii > 57) )
  16627. {
  16628. isSuccess = ConfigurationStatus_Rejected;
  16629. }
  16630. else
  16631. {
  16632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16633. isSuccess = ConfigurationStatus_Accepted;
  16634. }
  16635. }
  16636. else
  16637. {
  16638. isSuccess = ConfigurationStatus_Rejected;
  16639. }
  16640. }
  16641. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16642. {
  16643. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16644. {
  16645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16646. isSuccess = ConfigurationStatus_Accepted;
  16647. }
  16648. else
  16649. {
  16650. isSuccess = ConfigurationStatus_Rejected;
  16651. }
  16652. }
  16653. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16654. {
  16655. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16656. {
  16657. check_ascii = value[0];
  16658. if( (check_ascii < 48) || (check_ascii > 57) )
  16659. {
  16660. isSuccess = ConfigurationStatus_Rejected;
  16661. }
  16662. else
  16663. {
  16664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16665. isSuccess = ConfigurationStatus_Accepted;
  16666. }
  16667. }
  16668. else
  16669. {
  16670. isSuccess = ConfigurationStatus_Rejected;
  16671. }
  16672. }
  16673. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16674. {
  16675. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16676. {
  16677. strcpy(str, (const char*)value);
  16678. for(int i = 0; str[i]; i++)
  16679. {
  16680. str[i] = tolower(str[i]);
  16681. }
  16682. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16683. isSuccess = ConfigurationStatus_Accepted;
  16684. }
  16685. else
  16686. {
  16687. isSuccess = ConfigurationStatus_Rejected;
  16688. }
  16689. }
  16690. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16691. {
  16692. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16693. {
  16694. check_ascii = value[0];
  16695. if( (check_ascii < 48) || (check_ascii > 57) )
  16696. {
  16697. isSuccess = ConfigurationStatus_Rejected;
  16698. }
  16699. else
  16700. {
  16701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16702. isSuccess = ConfigurationStatus_Accepted;
  16703. }
  16704. }
  16705. else
  16706. {
  16707. isSuccess = ConfigurationStatus_Rejected;
  16708. }
  16709. }
  16710. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16711. return isSuccess;
  16712. }
  16713. int TransactionMessageAttemptsGet(void)
  16714. {
  16715. return TransactionMessageAttemptsValue;
  16716. }
  16717. int FirstHeartBeatResponse(void)
  16718. {
  16719. return FirstHeartBeat;
  16720. }
  16721. int TransactionMessageRetryIntervalGet(void)
  16722. {
  16723. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16724. }
  16725. int ReadHttpStatus(int sock)
  16726. {
  16727. //char c;
  16728. char buff[1024]="",*ptr=buff+1;
  16729. int bytes_received, status;
  16730. DEBUG_INFO("Begin Response ..\n");
  16731. while((bytes_received = recv(sock, ptr, 1, 0))){
  16732. if(bytes_received==-1){
  16733. perror("ReadHttpStatus");
  16734. exit(1);
  16735. }
  16736. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16737. ptr++;
  16738. }
  16739. *ptr=0;
  16740. ptr=buff+1;
  16741. sscanf(ptr,"%*s %d ", &status);
  16742. DEBUG_INFO("%s\n",ptr);
  16743. DEBUG_INFO("status=%d\n",status);
  16744. DEBUG_INFO("End Response ..\n");
  16745. return (bytes_received>0)?status:0;
  16746. }
  16747. //the only filed that it parsed is 'Content-Length'
  16748. int ParseHeader(int sock)
  16749. {
  16750. //char c;
  16751. char buff[1024]="",*ptr=buff+4;
  16752. int bytes_received;
  16753. DEBUG_INFO("Begin HEADER ..\n");
  16754. while((bytes_received = recv(sock, ptr, 1, 0))){
  16755. if(bytes_received==-1){
  16756. perror("Parse Header");
  16757. exit(1);
  16758. }
  16759. if(
  16760. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16761. (ptr[-1]=='\r') && (*ptr=='\n' )
  16762. ) break;
  16763. ptr++;
  16764. }
  16765. *ptr=0;
  16766. ptr=buff+4;
  16767. //printf("%s",ptr);
  16768. if(bytes_received){
  16769. ptr=strstr(ptr,"Content-Length:");
  16770. if(ptr){
  16771. sscanf(ptr,"%*s %d",&bytes_received);
  16772. }else
  16773. bytes_received=-1; //unknown size
  16774. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16775. }
  16776. DEBUG_INFO("End HEADER ..\n");
  16777. return bytes_received ;
  16778. }
  16779. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16780. {
  16781. int result = TRUE;
  16782. char rmFileCmd[100]={0};
  16783. char FilePath[100]={0};
  16784. char ftpbuf[200];
  16785. int systemresult;
  16786. sprintf(FilePath,"/mnt/%s",filename);
  16787. system("ping 8.8.8.8 &");
  16788. if((access(FilePath,F_OK))!=-1)
  16789. {
  16790. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16791. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16792. system(rmFileCmd);
  16793. }
  16794. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16795. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16796. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16797. systemresult = system(ftpbuf);
  16798. if(systemresult != 0)
  16799. {
  16800. DEBUG_INFO("http DownLoad error!\n");
  16801. result = FALSE;
  16802. }
  16803. system("pkill ping");
  16804. return result;
  16805. }
  16806. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16807. {
  16808. int result = TRUE;
  16809. char rmFileCmd[100]={0};
  16810. char FilePath[100]={0};
  16811. char ftpbuf[200];
  16812. int systemresult;
  16813. sprintf(FilePath,"/mnt/%s",filename);
  16814. system("ping 8.8.8.8 &");
  16815. if((access(FilePath,F_OK))!=-1)
  16816. {
  16817. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16818. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16819. system(rmFileCmd);
  16820. }
  16821. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16822. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16823. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16824. systemresult = system(ftpbuf);
  16825. if(systemresult != 0)
  16826. {
  16827. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16828. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16829. systemresult = system(ftpbuf);
  16830. if(systemresult != 0)
  16831. {
  16832. DEBUG_WARN("wget error!\n");
  16833. result = FALSE;
  16834. }
  16835. }
  16836. system("pkill ping");
  16837. return result;
  16838. }
  16839. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16840. {
  16841. char rmFileCmd[100]={0};
  16842. char FilePath[100]={0};
  16843. char buf[512];
  16844. int systemresult = 0;
  16845. //DEBUG_INFO("filename=%s\n",filename);
  16846. //DEBUG_INFO("url=%s\n",url);
  16847. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16848. if((access(FilePath,F_OK))!=-1)
  16849. {
  16850. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16851. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16852. system(rmFileCmd);
  16853. }
  16854. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16855. if(fp == NULL)
  16856. {
  16857. DEBUG_INFO("log is NULL\n");
  16858. return FALSE;
  16859. }
  16860. else
  16861. {
  16862. fprintf(fp, "%s\n", url);
  16863. fprintf(fp, "%s\n", filename);
  16864. fclose(fp);
  16865. }
  16866. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16867. if(phpFP == NULL)
  16868. {
  16869. DEBUG_INFO("PHP upload fail.\n");
  16870. return FALSE;
  16871. }
  16872. else
  16873. {
  16874. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16875. {
  16876. if(strstr(buf, "result") != NULL)
  16877. {
  16878. sscanf(buf, "result: %d", &systemresult);
  16879. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16880. }
  16881. }
  16882. pclose(phpFP);
  16883. }
  16884. if(systemresult != 1)
  16885. {
  16886. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  16887. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  16888. if(phpFP == NULL)
  16889. {
  16890. DEBUG_WARN("PHP PUT upload fail.\n");
  16891. return FALSE;
  16892. }
  16893. else
  16894. {
  16895. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16896. {
  16897. if(strstr(buf, "result") != NULL)
  16898. {
  16899. sscanf(buf, "result: %d", &systemresult);
  16900. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  16901. }
  16902. }
  16903. pclose(phpFP);
  16904. }
  16905. }
  16906. return TRUE;
  16907. }
  16908. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16909. {
  16910. int result = FALSE;
  16911. char ftpbuf[200];
  16912. int systemresult;
  16913. /*
  16914. // Domaind name transfer to IP address
  16915. struct hostent* server;
  16916. char *IPbuffer;
  16917. server = gethostbyname(location);
  16918. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16919. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16920. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16921. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16922. systemresult = system(ftpbuf);
  16923. if(systemresult != 0)
  16924. {
  16925. DEBUG_INFO("ftpput error!\n");
  16926. }
  16927. else
  16928. {
  16929. result = TRUE;
  16930. DEBUG_INFO("ftpput OK!\n");
  16931. }
  16932. return result;
  16933. }
  16934. int GetOcppServerURL()
  16935. {
  16936. int result = FALSE;
  16937. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16938. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16939. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16940. struct yuarel url;
  16941. char urlStr[512];
  16942. // OCPPPH only
  16943. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16944. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16945. {
  16946. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16947. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16948. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16949. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16950. if(yuarel_parse(&url, urlStr) != -1)
  16951. {
  16952. sprintf(OcppProtocol, "%s", url.scheme);
  16953. sprintf(OcppHost, "%s", url.host);
  16954. if(url.path == NULL)
  16955. OcppTempPath[0] = '\0';
  16956. else
  16957. sprintf(OcppTempPath, "%s", url.path);
  16958. if(url.port == 0)
  16959. {
  16960. if(strcmp(OcppProtocol, "wss") == 0)
  16961. OcppPort = 443;
  16962. else
  16963. OcppPort = 80;
  16964. }
  16965. else
  16966. OcppPort = url.port;
  16967. result = TRUE;
  16968. }
  16969. }
  16970. else
  16971. {
  16972. strcpy(OcppHost,"");
  16973. }
  16974. return result;
  16975. }
  16976. int GetOcppPath()
  16977. {
  16978. int result = FALSE;
  16979. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16980. {
  16981. if(OcppTempPath == NULL)
  16982. {
  16983. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16984. }
  16985. else
  16986. {
  16987. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16988. }
  16989. result = TRUE;
  16990. goto End;
  16991. }
  16992. else
  16993. {
  16994. strcpy(OcppPath,"");
  16995. }
  16996. End:
  16997. return result;
  16998. }
  16999. int GetOcppPort()
  17000. {
  17001. return OcppPort;
  17002. }
  17003. int GetOcppConnStatus(void)
  17004. {
  17005. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17006. }
  17007. void SetOcppConnStatus(uint8_t status)
  17008. {
  17009. ShmOCPP16DataPH->OcppConnStatus = status;
  17010. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17011. }
  17012. int GetHeartBeatWithNOResponse(void)
  17013. {
  17014. return HeartBeatWithNOResponse;
  17015. }
  17016. void SetHeartBeatWithNOResponse(void)
  17017. {
  17018. HeartBeatWithNOResponse = 0;
  17019. }
  17020. void GetStartTransactionIdTag(int gun_index)
  17021. {
  17022. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17023. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17024. }
  17025. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17026. {
  17027. char ch;
  17028. FILE *fptr1;
  17029. int temptransactionId;
  17030. char str[100]={0};
  17031. temptransactionId = 0;
  17032. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17033. {
  17034. DEBUG_INFO("IdTag is empty.\n");
  17035. return temptransactionId;
  17036. }
  17037. /*------ Read the file ----------------*/
  17038. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17039. if (!fptr1)
  17040. {
  17041. DEBUG_INFO("QueueTransactionId file open error.\n");
  17042. //printf(" File not found or unable to open the input file!!\n");
  17043. return temptransactionId;
  17044. }
  17045. ch=fgetc(fptr1);
  17046. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17047. rewind(fptr1);
  17048. if(ch!=EOF)
  17049. {
  17050. // printf("%c",ch);
  17051. while (fgets(str, 100, fptr1) != NULL)
  17052. {
  17053. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17054. if(str[0]=='\0')
  17055. {
  17056. break;
  17057. }
  17058. char *revbuf[8] = {0}; // Variable store string split
  17059. int num = 0;// Quantity after string split
  17060. DEBUG_INFO("Transaction queue data= %s\n", str);
  17061. splitstring(str,",",revbuf,&num); // String split
  17062. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17063. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17064. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17065. DEBUG_INFO("------------------------------\n");
  17066. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17067. {
  17068. if(isStopTransaction)
  17069. {
  17070. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17071. {
  17072. temptransactionId = atoi(revbuf[2]);
  17073. //break;
  17074. }
  17075. }
  17076. else
  17077. {
  17078. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17079. {
  17080. temptransactionId = atoi(revbuf[2]);
  17081. //break;
  17082. }
  17083. }
  17084. }
  17085. }
  17086. }
  17087. else
  17088. DEBUG_INFO("EOF\n");
  17089. fclose(fptr1);
  17090. /*------- End of reading ---------------*/
  17091. return temptransactionId;
  17092. }
  17093. void SetTransactionIdZero(int transactionId)
  17094. {
  17095. char ch;
  17096. FILE *fptr1, *fptr2;
  17097. int temptransactionId = 0;
  17098. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17099. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17100. if (!fptr1)
  17101. {
  17102. //printf(" File not found or unable to open the input file!!\n");
  17103. return ;
  17104. }
  17105. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17106. if (!fptr2)
  17107. {
  17108. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17109. fclose(fptr1);
  17110. return ;
  17111. }
  17112. ch=fgetc(fptr1);
  17113. rewind(fptr1);
  17114. if(ch!=EOF)
  17115. {
  17116. // copy all contents to the temporary file except the specific line
  17117. while (fgets(str, 100, fptr1) != NULL)
  17118. {
  17119. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17120. if(str[0]=='\0')
  17121. {
  17122. break;
  17123. }
  17124. char *revbuf[8] = {0};
  17125. int num = 0;
  17126. strcpy(strtemp, str);
  17127. splitstring(str,",",revbuf,&num);
  17128. if(revbuf[2][0] != '\0')
  17129. {
  17130. temptransactionId = atoi(revbuf[2]);
  17131. if(transactionId != temptransactionId)
  17132. {
  17133. fprintf(fptr2, "%s\n", strtemp);
  17134. }
  17135. }
  17136. }
  17137. }
  17138. fclose(fptr1);
  17139. fclose(fptr2);
  17140. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17141. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17142. /*------ Read the file ----------------*/
  17143. }
  17144. int InternetDisconnect(void)
  17145. {
  17146. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17147. }
  17148. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17149. void storeTempStopTransaction(int gun_index)
  17150. {
  17151. char guid[37]={0};
  17152. int tempIndex = 0;
  17153. char TempStopTransaction[256];
  17154. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17155. DEBUG_INFO("storeTempStopTransaction...\n");
  17156. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17157. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17158. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17159. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17160. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17161. {
  17162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17163. {
  17164. tempIndex = ((gun_index==2) ? 1: 0);
  17165. }
  17166. else
  17167. {
  17168. tempIndex = gun_index;
  17169. }
  17170. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17171. {
  17172. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17173. {
  17174. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17175. }
  17176. }// END OF CHAdeMO_QUANTITY
  17177. }
  17178. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17179. {
  17180. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17181. {
  17182. tempIndex = ((gun_index==2) ? 1: 0);
  17183. }
  17184. else
  17185. {
  17186. tempIndex = gun_index;
  17187. }
  17188. for (int index = 0; index < CCS_QUANTITY; index++)
  17189. {
  17190. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17191. {
  17192. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17193. }
  17194. }// END OF CCS_QUANTITY
  17195. }
  17196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17197. {
  17198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17199. {
  17200. tempIndex = ((gun_index==2) ? 1: 0);
  17201. }
  17202. else
  17203. {
  17204. tempIndex = gun_index;
  17205. }
  17206. for (int index = 0; index < GB_QUANTITY; index++)
  17207. {
  17208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17209. {
  17210. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17211. }
  17212. }// END OF GB_QUANTITY
  17213. }
  17214. else if(gunType[gun_index] == GUN_TYPE_DO)
  17215. {
  17216. tempIndex = gun_index;
  17217. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17218. {
  17219. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17220. {
  17221. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17222. }
  17223. }
  17224. }
  17225. else
  17226. {
  17227. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17228. {
  17229. tempIndex = 2;
  17230. }
  17231. else
  17232. {
  17233. tempIndex = gun_index;
  17234. }
  17235. for (int index = 0; index < AC_QUANTITY; index++)
  17236. {
  17237. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17238. {
  17239. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17240. }
  17241. }// END OF AC_QUANTITY
  17242. }
  17243. //Stop Transaction Time
  17244. struct timeval tmnow;
  17245. struct tm *tm;
  17246. char buf[28];//, usec_buf[6];
  17247. gettimeofday(&tmnow, NULL);
  17248. time_t t;
  17249. t = time(NULL);
  17250. /*UTC time and date*/
  17251. tm = gmtime(&t);
  17252. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17253. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17254. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17255. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17256. random_uuid(guid);
  17257. /***********************************transactionData******************************************************/
  17258. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17260. //=================================
  17261. //1. Transaction_Begin
  17262. //=================================
  17263. //============================== Energy.Active.Import.Interval ===========================================
  17264. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17265. {
  17266. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  17270. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17271. 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))
  17272. {
  17273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17274. }
  17275. else
  17276. {
  17277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17278. }
  17279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17281. }
  17282. //=================================
  17283. //2. Transaction_End
  17284. //=================================
  17285. //2.1====================================== Current.Import L1 ==============================================
  17286. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17287. {
  17288. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17289. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17290. {
  17291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17292. {
  17293. tempIndex = ((gun_index==2) ? 1: 0);
  17294. }
  17295. else
  17296. {
  17297. tempIndex = gun_index;
  17298. }
  17299. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17300. {
  17301. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17302. {
  17303. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17304. }
  17305. }// End of for CHAdeMO_QUANTITY
  17306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17307. }
  17308. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17309. {
  17310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17311. {
  17312. tempIndex = ((gun_index==2) ? 1: 0);
  17313. }
  17314. else
  17315. {
  17316. tempIndex = gun_index;
  17317. }
  17318. for (int index = 0; index < CCS_QUANTITY; index++)
  17319. {
  17320. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17321. {
  17322. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17323. }
  17324. }// End of for CCS_QUANTITY
  17325. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17326. }
  17327. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17328. {
  17329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17330. {
  17331. tempIndex = ((gun_index==2) ? 1: 0);
  17332. }
  17333. else
  17334. {
  17335. tempIndex = gun_index;
  17336. }
  17337. for (int index = 0; index < GB_QUANTITY; index++)
  17338. {
  17339. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17340. {
  17341. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17342. }
  17343. }// End of for GB_QUANTITY
  17344. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17345. }
  17346. else if(gunType[gun_index] == GUN_TYPE_DO)
  17347. {
  17348. tempIndex = gun_index;
  17349. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17350. {
  17351. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17352. {
  17353. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17354. }
  17355. }
  17356. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17357. }
  17358. else
  17359. {
  17360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17361. {
  17362. tempIndex = 2;
  17363. }
  17364. else
  17365. {
  17366. tempIndex = gun_index;
  17367. }
  17368. for (int index = 0; index < AC_QUANTITY; index++)
  17369. {
  17370. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17371. {
  17372. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17373. }
  17374. }// End of for AC_QUANTITY
  17375. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17376. }
  17377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17380. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17382. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17383. }
  17384. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17385. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17386. {
  17387. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17389. {
  17390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17391. {
  17392. tempIndex = ((gun_index==2) ? 1: 0);
  17393. }
  17394. else
  17395. {
  17396. tempIndex = gun_index;
  17397. }
  17398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17399. {
  17400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17401. {
  17402. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17403. }
  17404. }// END OF CHAdeMO_QUANTITY
  17405. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17406. }
  17407. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17408. {
  17409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17410. {
  17411. tempIndex = ((gun_index==2) ? 1: 0);
  17412. }
  17413. else
  17414. {
  17415. tempIndex = gun_index;
  17416. }
  17417. for (int index = 0; index < CCS_QUANTITY; index++)
  17418. {
  17419. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17420. {
  17421. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17422. }
  17423. }// END OF CCS_QUANTITY
  17424. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17425. }
  17426. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17427. {
  17428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17429. {
  17430. tempIndex = ((gun_index==2) ? 1: 0);
  17431. }
  17432. else
  17433. {
  17434. tempIndex = gun_index;
  17435. }
  17436. for (int index = 0; index < GB_QUANTITY; index++)
  17437. {
  17438. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17439. {
  17440. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17441. }
  17442. }// END OF GB_QUANTITY
  17443. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17444. }
  17445. else if(gunType[gun_index] == GUN_TYPE_DO)
  17446. {
  17447. tempIndex = gun_index;
  17448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17449. {
  17450. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17451. {
  17452. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17453. }
  17454. }
  17455. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17456. }
  17457. else
  17458. {
  17459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17460. {
  17461. tempIndex = 2;
  17462. }
  17463. else
  17464. {
  17465. tempIndex = gun_index;
  17466. }
  17467. for (int index = 0; index < AC_QUANTITY; index++)
  17468. {
  17469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17470. {
  17471. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17472. }
  17473. }// END OF AC_QUANTITY
  17474. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17475. }
  17476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17479. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17482. }
  17483. //2.3====================================== Power.Active.Import =========================================
  17484. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17485. {
  17486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17487. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17488. {
  17489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17490. {
  17491. tempIndex = ((gun_index==2) ? 1: 0);
  17492. }
  17493. else
  17494. {
  17495. tempIndex = gun_index;
  17496. }
  17497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17498. {
  17499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17500. {
  17501. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17502. }
  17503. } // End for CHAdeMO_QUANTITY
  17504. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17505. }
  17506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17507. {
  17508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17509. {
  17510. tempIndex = ((gun_index==2) ? 1: 0);
  17511. }
  17512. else
  17513. {
  17514. tempIndex = gun_index;
  17515. }
  17516. for (int index = 0; index < CCS_QUANTITY; index++)
  17517. {
  17518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17519. {
  17520. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17521. }
  17522. } // END for CCS_QUANTITY
  17523. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17524. }
  17525. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17526. {
  17527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17528. {
  17529. tempIndex = ((gun_index==2) ? 1: 0);
  17530. }
  17531. else
  17532. {
  17533. tempIndex = gun_index;
  17534. }
  17535. for (int index = 0; index < GB_QUANTITY; index++)
  17536. {
  17537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17538. {
  17539. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17540. }
  17541. }// END for GB_QUANTITY
  17542. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17543. }
  17544. else if(gunType[gun_index] == GUN_TYPE_DO)
  17545. {
  17546. tempIndex = gun_index;
  17547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17548. {
  17549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17550. {
  17551. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17552. }
  17553. }
  17554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17555. }
  17556. else
  17557. {
  17558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17559. {
  17560. tempIndex = 2;
  17561. }
  17562. else
  17563. {
  17564. tempIndex = gun_index;
  17565. }
  17566. for (int index = 0; index < AC_QUANTITY; index++)
  17567. {
  17568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17569. {
  17570. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17571. }
  17572. } // END for AC_QUANTITY
  17573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17574. }
  17575. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17576. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17577. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17578. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17581. }
  17582. //2.4====================================== Voltage L1 ====================================================
  17583. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17584. {
  17585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17587. {
  17588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17589. {
  17590. tempIndex = ((gun_index==2) ? 1: 0);
  17591. }
  17592. else
  17593. {
  17594. tempIndex = gun_index;
  17595. }
  17596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17597. {
  17598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17599. {
  17600. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17601. }
  17602. } // END OF FOR CHAdeMO_QUANTITY
  17603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17604. }
  17605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17606. {
  17607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17608. {
  17609. tempIndex = ((gun_index==2) ? 1: 0);
  17610. }
  17611. else
  17612. {
  17613. tempIndex = gun_index;
  17614. }
  17615. for (int index = 0; index < CCS_QUANTITY; index++)
  17616. {
  17617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17618. {
  17619. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17620. }
  17621. } // END OF FOR CCS_QUANTITY
  17622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17623. }
  17624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17625. {
  17626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17627. {
  17628. tempIndex = ((gun_index==2) ? 1: 0);
  17629. }
  17630. else
  17631. {
  17632. tempIndex = gun_index;
  17633. }
  17634. for (int index = 0; index < GB_QUANTITY; index++)
  17635. {
  17636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17637. {
  17638. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17639. }
  17640. } // END OF FOR GB_QUANTITY
  17641. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17642. }
  17643. else if(gunType[gun_index] == GUN_TYPE_DO)
  17644. {
  17645. tempIndex = gun_index;
  17646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17647. {
  17648. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17649. {
  17650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17651. }
  17652. }
  17653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17654. }
  17655. else
  17656. {
  17657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17658. {
  17659. tempIndex = 2;
  17660. }
  17661. else
  17662. {
  17663. tempIndex = gun_index;
  17664. }
  17665. for (int index = 0; index < AC_QUANTITY; index++)
  17666. {
  17667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17668. {
  17669. 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
  17670. }
  17671. } // END OF FOR AC_QUANTITY
  17672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17673. }
  17674. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17675. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17677. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17680. }
  17681. //2.5============================================== End SoC =========================================================
  17682. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17683. {
  17684. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17685. 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))
  17686. {
  17687. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17688. {
  17689. tempIndex = ((gun_index==2) ? 1: 0);
  17690. }
  17691. else
  17692. {
  17693. tempIndex = gun_index;
  17694. }
  17695. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17696. {
  17697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17698. {
  17699. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17700. {
  17701. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17702. }
  17703. }
  17704. }
  17705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17706. {
  17707. for (int index = 0; index < CCS_QUANTITY; index++)
  17708. {
  17709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17710. {
  17711. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17712. }
  17713. }
  17714. }
  17715. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17716. {
  17717. for (int index = 0; index < GB_QUANTITY; index++)
  17718. {
  17719. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17720. {
  17721. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17722. }
  17723. }
  17724. }
  17725. else if(gunType[gun_index] == GUN_TYPE_DO)
  17726. {
  17727. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17728. {
  17729. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17730. {
  17731. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17732. }
  17733. }
  17734. }
  17735. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17741. } // END FOR DC CASE
  17742. }
  17743. //2.6====================================== Current.Import L2 ==============================================
  17744. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17745. {
  17746. // AC 3 phase L2 current
  17747. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17748. {
  17749. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17750. {
  17751. tempIndex = 2;
  17752. }
  17753. else
  17754. {
  17755. tempIndex = gun_index;
  17756. }
  17757. for (int index = 0; index < AC_QUANTITY; index++)
  17758. {
  17759. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17760. {
  17761. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17762. }
  17763. }// End of for AC_QUANTITY
  17764. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17765. }
  17766. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17767. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17768. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17770. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17771. }
  17772. //2.7====================================== Current.Import L3 ==============================================
  17773. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17774. {
  17775. // AC 3 phase L3 current
  17776. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17777. {
  17778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17779. {
  17780. tempIndex = 2;
  17781. }
  17782. else
  17783. {
  17784. tempIndex = gun_index;
  17785. }
  17786. for (int index = 0; index < AC_QUANTITY; index++)
  17787. {
  17788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17789. {
  17790. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17791. }
  17792. }// End of for AC_QUANTITY
  17793. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17794. }
  17795. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17800. }
  17801. //2.9====================================== Voltage L2 ====================================================
  17802. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17803. {
  17804. // AC 3 phase L2 volatge
  17805. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17806. {
  17807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17808. {
  17809. tempIndex = 2;
  17810. }
  17811. else
  17812. {
  17813. tempIndex = gun_index;
  17814. }
  17815. for (int index = 0; index < AC_QUANTITY; index++)
  17816. {
  17817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17818. {
  17819. 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
  17820. }
  17821. } // END OF FOR AC_QUANTITY
  17822. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17823. }
  17824. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17825. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17829. }
  17830. //2.10====================================== Voltage L3 ====================================================
  17831. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17832. {
  17833. // AC 3 phase L3 volatge
  17834. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17835. {
  17836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17837. {
  17838. tempIndex = 2;
  17839. }
  17840. else
  17841. {
  17842. tempIndex = gun_index;
  17843. }
  17844. for (int index = 0; index < AC_QUANTITY; index++)
  17845. {
  17846. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17847. {
  17848. 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
  17849. }
  17850. } // END OF FOR AC_QUANTITY
  17851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17852. }
  17853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17855. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17858. }
  17859. //====================== Start SoC ================================
  17860. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17861. {
  17862. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17863. 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))
  17864. {
  17865. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17866. {
  17867. tempIndex = ((gun_index==2) ? 1: 0);
  17868. }
  17869. else
  17870. {
  17871. tempIndex = gun_index;
  17872. }
  17873. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17874. {
  17875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17876. {
  17877. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17878. {
  17879. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17880. }
  17881. }
  17882. }
  17883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17884. {
  17885. for (int index = 0; index < CCS_QUANTITY; index++)
  17886. {
  17887. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17888. {
  17889. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17890. }
  17891. }
  17892. }
  17893. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17894. {
  17895. for (int index = 0; index < GB_QUANTITY; index++)
  17896. {
  17897. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17898. {
  17899. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17900. }
  17901. }
  17902. }
  17903. else if(gunType[gun_index] == GUN_TYPE_DO)
  17904. {
  17905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17906. {
  17907. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17908. {
  17909. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17910. }
  17911. }
  17912. }
  17913. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17914. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17916. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17919. } // END FOR DC CASE
  17920. }
  17921. //======================================== Message create ==============================================
  17922. json_object *StopTransaction = json_object_new_object();
  17923. json_object *transactionDatas = json_object_new_array();
  17924. json_object *sampledValues = json_object_new_array();
  17925. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17926. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17927. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17928. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17929. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17930. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17931. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17932. {
  17933. json_object *transactionData = json_object_new_object();
  17934. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17935. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17936. {
  17937. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17938. {
  17939. json_object *sampledValue = json_object_new_object();
  17940. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17941. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17942. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17943. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17944. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17945. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17946. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17947. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17948. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17949. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17950. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17951. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17952. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17953. json_object_array_add(sampledValues, sampledValue);
  17954. }
  17955. }
  17956. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17957. json_object_array_add(transactionDatas, transactionData);
  17958. }
  17959. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17960. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17961. ,MESSAGE_TYPE_CALL
  17962. ,guid
  17963. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17964. json_object_put(StopTransaction);
  17965. // Check File "TempStopTransaction" Exist
  17966. if((access(TempStopTransaction,F_OK))!=-1)
  17967. {
  17968. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17969. fclose(fopen(TempStopTransaction, "w"));
  17970. }
  17971. else
  17972. {
  17973. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17974. FILE *log = fopen(TempStopTransaction, "w+");
  17975. if(log == NULL)
  17976. {
  17977. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17978. return ;
  17979. }
  17980. else
  17981. {
  17982. fclose(log);
  17983. }
  17984. }
  17985. //Add TempStopTransaction | Update TempStopTransaction
  17986. // open file for writing
  17987. FILE *outfile;
  17988. outfile = fopen (TempStopTransaction, "a");
  17989. //DEBUG_INFO("data = %s\n", queuedata);
  17990. fputs(queuedata, outfile);
  17991. fputs("\n", outfile);
  17992. fclose (outfile);
  17993. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17994. }
  17995. void checkTempStopTransaction(int gun_index)
  17996. {
  17997. FILE *fptr1;
  17998. char ch;
  17999. char str[QUEUE_MESSAGE_LENGTH]={0};
  18000. char guid[37]={0};
  18001. char tempdata[65]={0};
  18002. char connectorStr[2]={0};
  18003. char TempStopTransaction[256];
  18004. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18005. fptr1 = fopen(TempStopTransaction, "r");
  18006. //TempStopTransaction格式: 槍號,StopTransaction封包
  18007. if (!fptr1)
  18008. {
  18009. //printf(" File not found or unable to open the input file!!\n");
  18010. return ;
  18011. }
  18012. ch=fgetc(fptr1);
  18013. //printf(" Now the content of the file %s is : \n",fname);
  18014. rewind(fptr1);
  18015. if(ch!=EOF)
  18016. {
  18017. // copy all contents to the temporary file except the specific line
  18018. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18019. {
  18020. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18021. if(str[0]=='\0')
  18022. {
  18023. break;
  18024. }
  18025. //TempStopTransaction格式: 槍號,StopTransaction封包
  18026. strncpy(connectorStr, str, 1);
  18027. if(atoi(connectorStr) != (gun_index+1))
  18028. {
  18029. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18030. fclose(fptr1);
  18031. return ;
  18032. }
  18033. //random_uuid(guid);
  18034. strncpy(guid, str+6, 36); //copy guid
  18035. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18036. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18037. {
  18038. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18039. }
  18040. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18041. OCPP_insert_transaction_msg(NO, str);
  18042. memset(str,0,ARRAY_SIZE(str));
  18043. }
  18044. }
  18045. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18046. fclose(fptr1);
  18047. remove(TempStopTransaction); // remove the original file
  18048. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18049. }
  18050. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18051. {
  18052. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18053. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18054. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18055. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18056. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18057. }
  18058. int GetWebSocketPingInterval(void)
  18059. {
  18060. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18061. }
  18062. int GetServerSign(void)
  18063. {
  18064. return server_sign;
  18065. }
  18066. uint8_t GetOcppSecurityProfile()
  18067. {
  18068. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18069. }
  18070. void GetOcppChargerBoxId(uint8_t *data)
  18071. {
  18072. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18073. }
  18074. void GetOcppSecurityPassword(uint8_t *data)
  18075. {
  18076. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18077. }
  18078. void SetOcppVersion(uint8_t *version)
  18079. {
  18080. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18081. DEBUG_INFO("ocpp version: %s\n", version);
  18082. if(strstr((char*)version, "ocpp1.6") != NULL)
  18083. {
  18084. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18085. }
  18086. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18087. {
  18088. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18089. system("pkill OcppBackend");
  18090. }
  18091. }
  18092. void SetServerSign(int value)
  18093. {
  18094. server_sign = value;
  18095. }
  18096. int GetBootNotificationInterval(void)
  18097. {
  18098. return BootNotificationInterval;
  18099. }
  18100. int GetInternetConn(void)
  18101. {
  18102. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18103. }
  18104. int GetBackendConnectionTimeout(void)
  18105. {
  18106. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18107. }
  18108. int isConnectorInitMode(int gun_index)
  18109. {
  18110. int tempIndex = 0;
  18111. int result = TRUE;
  18112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18114. {
  18115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18116. {
  18117. tempIndex = ((gun_index==2) ? 1: 0);
  18118. }
  18119. else
  18120. {
  18121. tempIndex = gun_index;
  18122. }
  18123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18124. {
  18125. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18126. {
  18127. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18128. } //end of the same index
  18129. }//end of for CHAdeMO_QUANTITY
  18130. }
  18131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18132. {
  18133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18134. {
  18135. tempIndex = ((gun_index==2) ? 1: 0);
  18136. }
  18137. else
  18138. {
  18139. tempIndex = gun_index;
  18140. }
  18141. for (int index = 0; index < CCS_QUANTITY; index++)
  18142. {
  18143. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18144. {
  18145. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18146. } //end of the same index
  18147. } // end of for CCS_QUANTITY
  18148. }
  18149. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18150. {
  18151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18152. {
  18153. tempIndex = ((gun_index==2) ? 1: 0);
  18154. }
  18155. else
  18156. {
  18157. tempIndex = gun_index;
  18158. }
  18159. for (int index = 0; index < GB_QUANTITY; index++)
  18160. {
  18161. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18162. {
  18163. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18164. } //end of the same index
  18165. } // end of for GB_QUANTITY
  18166. }
  18167. else if(gunType[gun_index] == GUN_TYPE_DO)
  18168. {
  18169. tempIndex = gun_index;
  18170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18171. {
  18172. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18173. {
  18174. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18175. } //end of the same index
  18176. }
  18177. }
  18178. else
  18179. {
  18180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18181. {
  18182. tempIndex = 2;
  18183. }
  18184. else
  18185. {
  18186. tempIndex = gun_index;
  18187. }
  18188. for (int index = 0; index < AC_QUANTITY; index++)
  18189. {
  18190. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18191. {
  18192. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18193. }//end of the same index
  18194. }//end of for AC_QUANTITY
  18195. }
  18196. return result;
  18197. }
  18198. void refreshProcDogTimer()
  18199. {
  18200. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18201. }
  18202. void InitialSystemValue(void)
  18203. {
  18204. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18205. locallistVersion=0;
  18206. BootNotificationInterval = 0;
  18207. authorizeRetryTimes = 0;
  18208. GunStatusInterval = 10;
  18209. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18210. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18211. //Hear Beat
  18212. HeartBeatWithNOResponse = 0;
  18213. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18214. FirstHeartBeat = 0;
  18215. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18216. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18217. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18218. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18219. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18220. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18221. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18222. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18223. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18224. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18225. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18226. //Status && ConnectorPlugIn Setting
  18227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18228. {
  18229. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18230. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18231. }
  18232. for (int index = 0; index < CCS_QUANTITY; index++)
  18233. {
  18234. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18235. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18236. }
  18237. for (int index = 0; index < GB_QUANTITY; index++)
  18238. {
  18239. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18240. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18241. }
  18242. for (int index = 0; index < AC_QUANTITY; index++)
  18243. {
  18244. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18245. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18246. }
  18247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18248. {
  18249. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18250. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18251. }
  18252. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18253. {
  18254. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18255. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18256. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18257. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18258. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18259. }
  18260. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18261. refreshStartTimer(&clientTime.Heartbeat);
  18262. sleep(1);
  18263. }
  18264. void LWS_Send(char *str)
  18265. {
  18266. //=====================================================
  18267. // Check InternetConn 0: disconnected, 1: connected
  18268. //====================================================
  18269. if(GetOcppConnStatus() == 0)
  18270. {
  18271. DEBUG_INFO("offline now !!!\n");
  18272. return;
  18273. }
  18274. // Only disable isWebsocketSendable operation initiated by charger
  18275. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18276. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18277. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18278. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18279. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18280. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18281. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18282. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18283. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18284. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18285. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18286. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18287. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18288. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18289. {
  18290. isWebsocketSendable = 0;
  18291. }
  18292. pthread_mutex_lock(&lock_send);
  18293. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18294. sprintf((char *)SendBuffer, "%s", str);
  18295. SendBufLen = strlen(str);
  18296. pthread_mutex_unlock(&lock_send);
  18297. lws_callback_on_writable(wsi_client);
  18298. //lws_service(context, 0);
  18299. //sleep(1);
  18300. }
  18301. void LWS_SendNow(char *str)
  18302. {
  18303. //=====================================================
  18304. // Check InternetConn 0: disconnected, 1: connected
  18305. //====================================================
  18306. if(GetOcppConnStatus() == 0)
  18307. {
  18308. DEBUG_INFO("offline now !!!\n");
  18309. return;
  18310. }
  18311. // Only disable isWebsocketSendable operation initiated by charger
  18312. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18313. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18314. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18315. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18316. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18317. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18318. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18319. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18320. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18321. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18322. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18323. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18324. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18325. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18326. {
  18327. isWebsocketSendable = 0;
  18328. }
  18329. pthread_mutex_lock(&lock_send);
  18330. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18331. sprintf((char *)SendBuffer, "%s", str);
  18332. SendBufLen = strlen(str);
  18333. pthread_mutex_unlock(&lock_send);
  18334. lws_callback_on_writable(wsi_client);
  18335. lws_service(context, 0);
  18336. //sleep(1);
  18337. }