MessageHandler.c 914 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675
  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. int result = -1;
  926. struct tm tmStart;
  927. struct timeb tbStart;
  928. struct tm tmStop;
  929. struct timeb tbStop;
  930. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  931. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  932. {
  933. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  934. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  935. tmStart.tm_year -= 1900;
  936. tmStart.tm_mon -= 1;
  937. tbStart.time = mktime(&tmStart);
  938. tbStart.millitm = 0;
  939. tmStop.tm_year -= 1900;
  940. tmStop.tm_mon -= 1;
  941. tbStop.time = mktime(&tmStop);
  942. tbStop.millitm = 0;
  943. result = DiffTimebSec(tbStart, tbStop);
  944. //DEBUG_INFO("getStartStop(): %d\n", result);
  945. }
  946. else
  947. {
  948. DEBUG_WARN("Start or stop date parsing error.\r\n");
  949. }
  950. return result;
  951. }
  952. int isOvertNow(uint8_t *start)
  953. {
  954. int result = NO;
  955. struct ParsingResult
  956. {
  957. int result;
  958. int scanedElement;
  959. int year;
  960. int month;
  961. int mday;
  962. int hour;
  963. int min;
  964. int sec;
  965. int tz_hour;
  966. int tz_min;
  967. float minSec;
  968. }parsingResult;
  969. struct tm tmStart;
  970. struct timeb tbStart;
  971. if(strstr((char*)start, ".") != NULL)
  972. {
  973. // Original data with mini second
  974. if(strstr((char*)start, "Z") != NULL)
  975. {
  976. // Original data with Z
  977. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  978. &parsingResult.year,
  979. &parsingResult.month,
  980. &parsingResult.mday,
  981. &parsingResult.hour,
  982. &parsingResult.min,
  983. &parsingResult.sec,
  984. &parsingResult.minSec);
  985. }
  986. else
  987. {
  988. // Original data without Z
  989. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  990. &parsingResult.year,
  991. &parsingResult.month,
  992. &parsingResult.mday,
  993. &parsingResult.hour,
  994. &parsingResult.min,
  995. &parsingResult.sec,
  996. &parsingResult.minSec,
  997. &parsingResult.tz_hour,
  998. &parsingResult.tz_min);
  999. }
  1000. }
  1001. else
  1002. {
  1003. // Original data without mini second
  1004. if(strstr((char*)start, "Z") != NULL)
  1005. {
  1006. // Original data with Z
  1007. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1008. &parsingResult.year,
  1009. &parsingResult.month,
  1010. &parsingResult.mday,
  1011. &parsingResult.hour,
  1012. &parsingResult.min,
  1013. &parsingResult.sec);
  1014. }
  1015. else
  1016. {
  1017. // Original data without Z
  1018. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1019. &parsingResult.year,
  1020. &parsingResult.month,
  1021. &parsingResult.mday,
  1022. &parsingResult.hour,
  1023. &parsingResult.min,
  1024. &parsingResult.sec,
  1025. &parsingResult.tz_hour,
  1026. &parsingResult.tz_min);
  1027. }
  1028. }
  1029. if(parsingResult.scanedElement >= 6)
  1030. {
  1031. tmStart.tm_year = parsingResult.year - 1900;
  1032. tmStart.tm_mon = parsingResult.month - 1;
  1033. tmStart.tm_mday = parsingResult.mday;
  1034. tmStart.tm_hour = parsingResult.hour;
  1035. tmStart.tm_min = parsingResult.min;
  1036. tmStart.tm_sec = parsingResult.sec;
  1037. tmStart.tm_gmtoff = 0;
  1038. tbStart.time = mktime(&tmStart);
  1039. tbStart.timezone = 0;
  1040. tbStart.millitm = 0;
  1041. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1042. if(DiffTimebWithNowSec(tbStart) <= 0)
  1043. result = NO;
  1044. else
  1045. result = YES;
  1046. }
  1047. else
  1048. {
  1049. DEBUG_WARN("Start date parsing error.\n");
  1050. }
  1051. return result;
  1052. }
  1053. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1054. {
  1055. int result = -1;
  1056. struct tm tmStart;
  1057. struct timeb tbStart;
  1058. struct tm tmStop;
  1059. struct timeb tbStop;
  1060. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1061. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1062. {
  1063. tmStart.tm_year -= 1900;
  1064. tmStart.tm_mon -= 1;
  1065. tbStart.time = mktime(&tmStart);
  1066. tbStart.millitm = 0;
  1067. tmStop.tm_year -= 1900;
  1068. tmStop.tm_mon -= 1;
  1069. tbStop.time = mktime(&tmStop);
  1070. tbStop.millitm = 0;
  1071. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1072. }
  1073. return result;
  1074. }
  1075. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1076. {
  1077. FILE *fp;
  1078. char profileFileName[128];
  1079. char *line = NULL;
  1080. size_t len = 0;
  1081. time_t CurrentTime;
  1082. struct tm *tmComposite;
  1083. struct StructChargingProfile maxProfile;
  1084. struct StructChargingProfile compositeProfile;
  1085. uint8_t limitMax=0;
  1086. int compositePeriodIdx = 0;
  1087. CurrentTime = time(NULL);
  1088. tmComposite=localtime(&CurrentTime);
  1089. 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);
  1090. if(isUnitA)
  1091. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1092. else
  1093. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1094. compositeProfile.ChargingSchedule.Duration = durationReq;
  1095. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1096. {
  1097. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1098. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1099. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1100. }
  1101. compositeProfile.ChargingProfileId = 0;
  1102. compositeProfile.StackLevel = 99 ;
  1103. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1104. maxProfile.ChargingProfileId = -1;
  1105. maxProfile.ChargingSchedule.Duration = -1;
  1106. system("rm -f /tmp/*.json");
  1107. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1108. // Search max profile
  1109. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1110. if((access(profileFileName, F_OK))!=-1)
  1111. {
  1112. fp = fopen(profileFileName, "r");
  1113. while(getline(&line, &len, fp) != -1)
  1114. {
  1115. json_object *obj = NULL;
  1116. obj = json_tokener_parse(line);
  1117. if(is_error(obj))
  1118. {
  1119. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1120. }
  1121. else
  1122. {
  1123. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1124. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1125. )
  1126. {
  1127. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1128. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1129. )
  1130. {
  1131. struct tm tmFrom, tmTo;
  1132. struct timeb tbFrom, tbTo;
  1133. 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) &&
  1134. (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))
  1135. {
  1136. tmFrom.tm_year -= 1900;
  1137. tmFrom.tm_mon -= 1;
  1138. tbFrom.time = mktime(&tmFrom);
  1139. tmTo.tm_year -= 1900;
  1140. tmTo.tm_mon -= 1;
  1141. tbTo.time = mktime(&tmTo);
  1142. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1143. {
  1144. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1145. {
  1146. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1147. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1149. }
  1150. maxProfile.ChargingProfileId = -1;
  1151. maxProfile.StackLevel = -1;
  1152. if(maxProfile.ChargingProfileId == -1)
  1153. DEBUG_INFO("MaxProfile found.\n");
  1154. else
  1155. DEBUG_INFO("MaxProfile updated.\n");
  1156. // Required item
  1157. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1158. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1159. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1160. if(isUnitA)
  1161. {
  1162. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1163. 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++)
  1164. {
  1165. 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"));
  1166. 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?
  1167. 3:
  1168. 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")));
  1169. 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")));
  1170. }
  1171. }
  1172. else
  1173. {
  1174. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1175. 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++)
  1176. {
  1177. 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"));
  1178. 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?
  1179. 3:
  1180. 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")));
  1181. 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));
  1182. }
  1183. }
  1184. // Optional item
  1185. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1186. {
  1187. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1188. }
  1189. else
  1190. {
  1191. sprintf((char*)maxProfile.ValidFrom, " ");
  1192. }
  1193. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1194. {
  1195. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1196. }
  1197. else
  1198. {
  1199. sprintf((char*)maxProfile.ValidTo, " ");
  1200. }
  1201. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1202. {
  1203. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1204. }
  1205. else
  1206. {
  1207. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1208. }
  1209. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1210. {
  1211. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1212. }
  1213. else
  1214. {
  1215. maxProfile.TransactionId = -1;
  1216. }
  1217. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1218. {
  1219. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1220. }
  1221. else
  1222. {
  1223. maxProfile.ChargingSchedule.Duration = 86400;
  1224. }
  1225. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1226. {
  1227. 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")));
  1228. }
  1229. else
  1230. {
  1231. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1232. }
  1233. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1234. {
  1235. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1236. }
  1237. else
  1238. {
  1239. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1240. }
  1241. }
  1242. }
  1243. }
  1244. else
  1245. {
  1246. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1247. {
  1248. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1249. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1250. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1251. }
  1252. maxProfile.ChargingProfileId = -1;
  1253. maxProfile.StackLevel = -1;
  1254. if(maxProfile.ChargingProfileId == -1)
  1255. DEBUG_INFO("MaxProfile found.\n");
  1256. else
  1257. DEBUG_INFO("MaxProfile updated.\n");
  1258. // Required item
  1259. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1260. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1261. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1262. if(isUnitA)
  1263. {
  1264. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1265. 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++)
  1266. {
  1267. 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"));
  1268. 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?
  1269. 3:
  1270. 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")));
  1271. 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")));
  1272. }
  1273. }
  1274. else
  1275. {
  1276. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1277. 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++)
  1278. {
  1279. 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"));
  1280. 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?
  1281. 3:
  1282. 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")));
  1283. 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));
  1284. }
  1285. }
  1286. // Optional item
  1287. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1288. {
  1289. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1290. }
  1291. else
  1292. {
  1293. sprintf((char*)maxProfile.ValidFrom, " ");
  1294. }
  1295. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1296. {
  1297. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1298. }
  1299. else
  1300. {
  1301. sprintf((char*)maxProfile.ValidTo, " ");
  1302. }
  1303. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1304. {
  1305. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1306. }
  1307. else
  1308. {
  1309. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1310. }
  1311. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1312. {
  1313. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1314. }
  1315. else
  1316. {
  1317. maxProfile.TransactionId = -1;
  1318. }
  1319. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1320. {
  1321. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1322. }
  1323. else
  1324. {
  1325. maxProfile.ChargingSchedule.Duration = 86400;
  1326. }
  1327. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1328. {
  1329. 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")));
  1330. }
  1331. else
  1332. {
  1333. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1334. }
  1335. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1336. {
  1337. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1338. }
  1339. else
  1340. {
  1341. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1342. }
  1343. }
  1344. }
  1345. }
  1346. json_object_put(obj);
  1347. }
  1348. fclose(fp);
  1349. /*
  1350. if(maxProfile.ChargingProfileId !=-1)
  1351. {
  1352. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1353. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1354. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1355. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1356. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1357. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1358. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1359. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1360. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1361. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1362. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1363. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1364. {
  1365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1366. {
  1367. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1368. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1369. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1370. }
  1371. }
  1372. }
  1373. else
  1374. DEBUG_INFO("MaxProfile not found.\n");
  1375. DEBUG_INFO("------------------------------------\n");*/
  1376. }
  1377. if(maxProfile.ChargingProfileId != -1)
  1378. {
  1379. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1380. {
  1381. if(maxProfile.ChargingSchedule.Duration != -1)
  1382. {
  1383. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1384. 0:
  1385. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1386. }
  1387. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1388. {
  1389. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1390. {
  1391. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1392. 0:
  1393. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1394. if(idxPeriod > 0)
  1395. {
  1396. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1397. {
  1398. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1405. {
  1406. if(maxProfile.ChargingSchedule.Duration != -1)
  1407. {
  1408. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1409. }
  1410. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1411. {
  1412. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1413. {
  1414. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1415. if(idxPeriod > 0)
  1416. {
  1417. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1418. {
  1419. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1420. }
  1421. }
  1422. }
  1423. }
  1424. }
  1425. else
  1426. {
  1427. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1428. {
  1429. if(maxProfile.ChargingSchedule.Duration != -1)
  1430. {
  1431. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1432. 0:
  1433. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1434. }
  1435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1436. {
  1437. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1438. {
  1439. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1440. 0:
  1441. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1442. if(idxPeriod > 0)
  1443. {
  1444. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1445. {
  1446. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. else
  1453. {
  1454. if(maxProfile.ChargingSchedule.Duration != -1)
  1455. {
  1456. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1457. 0:
  1458. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1459. }
  1460. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1461. {
  1462. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1463. {
  1464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1465. 0:
  1466. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1467. if(idxPeriod > 0)
  1468. {
  1469. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1470. {
  1471. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. }
  1478. /*
  1479. DEBUG_INFO("MaxProfile after align.\n");
  1480. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1481. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1482. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1483. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1484. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1485. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1486. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1487. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1488. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1489. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1490. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1491. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1492. {
  1493. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1494. {
  1495. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1496. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1497. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1498. }
  1499. }
  1500. DEBUG_INFO("------------------------------------\n");*/
  1501. }
  1502. // Find each profile period quantity
  1503. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1504. {
  1505. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1506. limitMax = idx+1;
  1507. }
  1508. if(maxProfile.ChargingProfileId != -1)
  1509. {
  1510. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1511. {
  1512. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1513. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1514. (maxProfile.ChargingSchedule.Duration > 0))
  1515. {
  1516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1517. {
  1518. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1519. compositePeriodIdx++;
  1520. }
  1521. else
  1522. {
  1523. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1524. }
  1525. }
  1526. }
  1527. }
  1528. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1529. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1530. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1531. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1532. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1533. {
  1534. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1535. {
  1536. compositeProfile.ChargingProfileId = 1;
  1537. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1538. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1539. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1540. }
  1541. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1542. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1543. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1544. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1545. }
  1546. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1547. if(line)
  1548. free(line);
  1549. }
  1550. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1551. {
  1552. FILE *fp;
  1553. char profileFileName[128];
  1554. char *line = NULL;
  1555. size_t len = 0;
  1556. time_t CurrentTime;
  1557. struct tm *tmComposite;
  1558. struct StructChargingProfile maxProfile;
  1559. struct StructChargingProfile defaultTxProfile;
  1560. struct StructChargingProfile txProfile;
  1561. struct StructChargingProfile compositeProfile;
  1562. struct StructChargingSchedulePeriod tmpPeriod;
  1563. uint8_t limitMax=0;
  1564. uint8_t limitDef=0;
  1565. uint8_t limitTx=0;
  1566. int compositePeriodIdx = 0;
  1567. CurrentTime = time(NULL);
  1568. tmComposite=localtime(&CurrentTime);
  1569. 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);
  1570. if(isUnitA)
  1571. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1572. else
  1573. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1574. compositeProfile.ChargingSchedule.Duration = durationReq;
  1575. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1576. {
  1577. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1578. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1579. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1580. }
  1581. compositeProfile.ChargingProfileId = 0;
  1582. compositeProfile.StackLevel = 99 ;
  1583. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1584. maxProfile.ChargingProfileId = -1;
  1585. defaultTxProfile.ChargingProfileId = -1;
  1586. txProfile.ChargingProfileId = -1;
  1587. maxProfile.ChargingSchedule.Duration = -1;
  1588. defaultTxProfile.ChargingSchedule.Duration = -1;
  1589. txProfile.ChargingSchedule.Duration = -1;
  1590. system("rm -f /tmp/*.json");
  1591. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1592. /*
  1593. * Search valid charging profile
  1594. */
  1595. //DEBUG_INFO("====================================\n");
  1596. // Search tx profile
  1597. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1598. if((access(profileFileName, F_OK))!=-1)
  1599. {
  1600. fp = fopen(profileFileName, "r");
  1601. while(getline(&line, &len, fp) != -1)
  1602. {
  1603. json_object *obj = NULL;
  1604. obj = json_tokener_parse(line);
  1605. if(is_error(obj))
  1606. {
  1607. DEBUG_ERROR("Parse txProfile from file error.\n");
  1608. }
  1609. else
  1610. {
  1611. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1612. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1613. )
  1614. {
  1615. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1616. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1617. )
  1618. {
  1619. struct tm tmFrom, tmTo;
  1620. struct timeb tbFrom, tbTo;
  1621. 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) &&
  1622. (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))
  1623. {
  1624. tmFrom.tm_year -= 1900;
  1625. tmFrom.tm_mon -= 1;
  1626. tbFrom.time = mktime(&tmFrom);
  1627. tmTo.tm_year -= 1900;
  1628. tmTo.tm_mon -= 1;
  1629. tbTo.time = mktime(&tmTo);
  1630. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1631. {
  1632. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1633. {
  1634. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1635. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1636. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1637. }
  1638. txProfile.ChargingProfileId = -1;
  1639. txProfile.StackLevel = -1;
  1640. if(txProfile.ChargingProfileId == -1)
  1641. DEBUG_INFO("TxProfile found.\n");
  1642. else
  1643. DEBUG_INFO("TxProfile updated.\n");
  1644. // Required item
  1645. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1646. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1647. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1648. if(isUnitA)
  1649. {
  1650. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1651. 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++)
  1652. {
  1653. 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"));
  1654. 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?
  1655. 3:
  1656. 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")));
  1657. 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")));
  1658. }
  1659. }
  1660. else
  1661. {
  1662. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1663. 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++)
  1664. {
  1665. 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"));
  1666. 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?
  1667. 3:
  1668. 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")));
  1669. 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));
  1670. }
  1671. }
  1672. // Optional item
  1673. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1674. {
  1675. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1676. }
  1677. else
  1678. {
  1679. sprintf((char*)txProfile.ValidFrom, " ");
  1680. }
  1681. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1682. {
  1683. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1684. }
  1685. else
  1686. {
  1687. sprintf((char*)txProfile.ValidTo, " ");
  1688. }
  1689. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1690. {
  1691. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1692. }
  1693. else
  1694. {
  1695. sprintf((char*)txProfile.RecurrencyKind, " ");
  1696. }
  1697. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1698. {
  1699. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1700. }
  1701. else
  1702. {
  1703. txProfile.TransactionId = -1;
  1704. }
  1705. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1706. {
  1707. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1708. }
  1709. else
  1710. {
  1711. txProfile.ChargingSchedule.Duration = 86400;
  1712. }
  1713. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1714. {
  1715. 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")));
  1716. }
  1717. else
  1718. {
  1719. 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));
  1720. }
  1721. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1722. {
  1723. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1724. }
  1725. else
  1726. {
  1727. txProfile.ChargingSchedule.MinChargingRate = -1;
  1728. }
  1729. }
  1730. }
  1731. }
  1732. else
  1733. {
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1737. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1738. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1739. }
  1740. txProfile.ChargingProfileId = -1;
  1741. txProfile.StackLevel = -1;
  1742. if(txProfile.ChargingProfileId == -1)
  1743. DEBUG_INFO("TxProfile found.\n");
  1744. else
  1745. DEBUG_INFO("TxProfile updated.\n");
  1746. // Required item
  1747. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1748. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1749. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1750. if(isUnitA)
  1751. {
  1752. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1753. 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++)
  1754. {
  1755. 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"));
  1756. 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?
  1757. 3:
  1758. 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")));
  1759. 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")));
  1760. }
  1761. }
  1762. else
  1763. {
  1764. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1765. 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++)
  1766. {
  1767. 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"));
  1768. 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?
  1769. 3:
  1770. 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")));
  1771. 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));
  1772. }
  1773. }
  1774. // Optional item
  1775. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1776. {
  1777. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1778. }
  1779. else
  1780. {
  1781. sprintf((char*)txProfile.ValidFrom, " ");
  1782. }
  1783. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1784. {
  1785. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1786. }
  1787. else
  1788. {
  1789. sprintf((char*)txProfile.ValidTo, " ");
  1790. }
  1791. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1792. {
  1793. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1794. }
  1795. else
  1796. {
  1797. sprintf((char*)txProfile.RecurrencyKind, " ");
  1798. }
  1799. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1800. {
  1801. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1802. }
  1803. else
  1804. {
  1805. txProfile.TransactionId = -1;
  1806. }
  1807. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1808. {
  1809. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1810. }
  1811. else
  1812. {
  1813. txProfile.ChargingSchedule.Duration = 86400;
  1814. }
  1815. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1816. {
  1817. 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")));
  1818. }
  1819. else
  1820. {
  1821. 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));
  1822. }
  1823. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1824. {
  1825. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1826. }
  1827. else
  1828. {
  1829. txProfile.ChargingSchedule.MinChargingRate = -1;
  1830. }
  1831. }
  1832. }
  1833. }
  1834. json_object_put(obj);
  1835. }
  1836. fclose(fp);
  1837. /*
  1838. if(txProfile.ChargingProfileId != -1)
  1839. {
  1840. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1841. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1842. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1843. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1844. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1845. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1846. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1847. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1848. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1849. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1850. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1852. {
  1853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1854. {
  1855. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1856. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1857. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1858. }
  1859. }
  1860. }
  1861. else
  1862. DEBUG_INFO("TxProfile not found.\n");*/
  1863. }
  1864. // Search default tx profile
  1865. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1866. if((access(profileFileName, F_OK))==-1)
  1867. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1868. if((access(profileFileName, F_OK))!=-1)
  1869. {
  1870. fp = fopen(profileFileName, "r");
  1871. while(getline(&line, &len, fp) != -1)
  1872. {
  1873. json_object *obj = NULL;
  1874. obj = json_tokener_parse(line);
  1875. if(is_error(obj))
  1876. {
  1877. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1878. }
  1879. else
  1880. {
  1881. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1882. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1883. )
  1884. {
  1885. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1886. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1887. )
  1888. {
  1889. struct tm tmFrom, tmTo;
  1890. struct timeb tbFrom, tbTo;
  1891. 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) &&
  1892. (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))
  1893. {
  1894. tmFrom.tm_year -= 1900;
  1895. tmFrom.tm_mon -= 1;
  1896. tbFrom.time = mktime(&tmFrom);
  1897. tmTo.tm_year -= 1900;
  1898. tmTo.tm_mon -= 1;
  1899. tbTo.time = mktime(&tmTo);
  1900. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1901. {
  1902. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1903. {
  1904. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1905. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1906. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1907. }
  1908. defaultTxProfile.ChargingProfileId = -1;
  1909. defaultTxProfile.StackLevel = -1;
  1910. if(defaultTxProfile.ChargingProfileId == -1)
  1911. DEBUG_INFO("TxDefaultProfile found.\n");
  1912. else
  1913. DEBUG_INFO("TxDefaultProfile updated.\n");
  1914. // Required item
  1915. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1916. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1917. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1918. if(isUnitA)
  1919. {
  1920. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1921. 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++)
  1922. {
  1923. 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"));
  1924. 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?
  1925. 3:
  1926. 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")));
  1927. 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")));
  1928. }
  1929. }
  1930. else
  1931. {
  1932. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1933. 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++)
  1934. {
  1935. 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"));
  1936. 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?
  1937. 3:
  1938. 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")));
  1939. 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));
  1940. }
  1941. }
  1942. // Optional item
  1943. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1944. {
  1945. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1946. }
  1947. else
  1948. {
  1949. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1950. }
  1951. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1952. {
  1953. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1954. }
  1955. else
  1956. {
  1957. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1958. }
  1959. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1960. {
  1961. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1962. }
  1963. else
  1964. {
  1965. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1966. }
  1967. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1968. {
  1969. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1970. }
  1971. else
  1972. {
  1973. defaultTxProfile.TransactionId = -1;
  1974. }
  1975. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1976. {
  1977. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1978. }
  1979. else
  1980. {
  1981. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1982. }
  1983. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1984. {
  1985. 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")));
  1986. }
  1987. else
  1988. {
  1989. 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));
  1990. }
  1991. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1992. {
  1993. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1994. }
  1995. else
  1996. {
  1997. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1998. }
  1999. }
  2000. }
  2001. }
  2002. else
  2003. {
  2004. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2005. {
  2006. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2007. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2008. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2009. }
  2010. defaultTxProfile.ChargingProfileId = -1;
  2011. defaultTxProfile.StackLevel = -1;
  2012. if(defaultTxProfile.ChargingProfileId == -1)
  2013. DEBUG_INFO("TxDefaultProfile found.\n");
  2014. else
  2015. DEBUG_INFO("TxDefaultProfile updated.\n");
  2016. // Required item
  2017. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2018. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2019. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2020. if(isUnitA)
  2021. {
  2022. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2023. 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++)
  2024. {
  2025. 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"));
  2026. 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?
  2027. 3:
  2028. 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")));
  2029. 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")));
  2030. }
  2031. }
  2032. else
  2033. {
  2034. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2035. 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++)
  2036. {
  2037. 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"));
  2038. 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?
  2039. 3:
  2040. 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")));
  2041. 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));
  2042. }
  2043. }
  2044. // Optional item
  2045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2046. {
  2047. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2048. }
  2049. else
  2050. {
  2051. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2052. }
  2053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2054. {
  2055. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2060. }
  2061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2062. {
  2063. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2064. }
  2065. else
  2066. {
  2067. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2068. }
  2069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2070. {
  2071. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2072. }
  2073. else
  2074. {
  2075. defaultTxProfile.TransactionId = -1;
  2076. }
  2077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2078. {
  2079. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2080. }
  2081. else
  2082. {
  2083. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2084. }
  2085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2086. {
  2087. 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")));
  2088. }
  2089. else
  2090. {
  2091. 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));
  2092. }
  2093. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2094. {
  2095. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2096. }
  2097. else
  2098. {
  2099. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2100. }
  2101. }
  2102. }
  2103. }
  2104. json_object_put(obj);
  2105. }
  2106. fclose(fp);
  2107. /*
  2108. if(defaultTxProfile.ChargingProfileId != -1)
  2109. {
  2110. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2111. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2112. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2113. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2114. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2115. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2116. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2117. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2118. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2119. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2120. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2121. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2122. {
  2123. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2124. {
  2125. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2126. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2127. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2128. }
  2129. }
  2130. }
  2131. else
  2132. DEBUG_INFO("TxDefaultProfile not found.\n");
  2133. DEBUG_INFO("------------------------------------\n");*/
  2134. }
  2135. // Search max profile
  2136. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2137. if((access(profileFileName, F_OK))!=-1)
  2138. {
  2139. fp = fopen(profileFileName, "r");
  2140. while(getline(&line, &len, fp) != -1)
  2141. {
  2142. json_object *obj = NULL;
  2143. obj = json_tokener_parse(line);
  2144. if(is_error(obj))
  2145. {
  2146. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2147. }
  2148. else
  2149. {
  2150. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2151. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2152. )
  2153. {
  2154. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2155. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2156. )
  2157. {
  2158. struct tm tmFrom, tmTo;
  2159. struct timeb tbFrom, tbTo;
  2160. 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) &&
  2161. (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))
  2162. {
  2163. tmFrom.tm_year -= 1900;
  2164. tmFrom.tm_mon -= 1;
  2165. tbFrom.time = mktime(&tmFrom);
  2166. tmTo.tm_year -= 1900;
  2167. tmTo.tm_mon -= 1;
  2168. tbTo.time = mktime(&tmTo);
  2169. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2170. {
  2171. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2172. {
  2173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2174. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2176. }
  2177. maxProfile.ChargingProfileId = -1;
  2178. maxProfile.StackLevel = -1;
  2179. if(maxProfile.ChargingProfileId == -1)
  2180. DEBUG_INFO("MaxProfile found.\n");
  2181. else
  2182. DEBUG_INFO("MaxProfile updated.\n");
  2183. // Required item
  2184. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2185. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2186. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2187. if(isUnitA)
  2188. {
  2189. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2190. 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++)
  2191. {
  2192. 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"));
  2193. 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?
  2194. 3:
  2195. 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")));
  2196. 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")));
  2197. }
  2198. }
  2199. else
  2200. {
  2201. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2202. 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++)
  2203. {
  2204. 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"));
  2205. 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?
  2206. 3:
  2207. 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")));
  2208. 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));
  2209. }
  2210. }
  2211. // Optional item
  2212. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2213. {
  2214. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2215. }
  2216. else
  2217. {
  2218. sprintf((char*)maxProfile.ValidFrom, " ");
  2219. }
  2220. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2221. {
  2222. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2223. }
  2224. else
  2225. {
  2226. sprintf((char*)maxProfile.ValidTo, " ");
  2227. }
  2228. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2229. {
  2230. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2231. }
  2232. else
  2233. {
  2234. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2235. }
  2236. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2237. {
  2238. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2239. }
  2240. else
  2241. {
  2242. maxProfile.TransactionId = -1;
  2243. }
  2244. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2245. {
  2246. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2247. }
  2248. else
  2249. {
  2250. maxProfile.ChargingSchedule.Duration = 86400;
  2251. }
  2252. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2253. {
  2254. 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")));
  2255. }
  2256. else
  2257. {
  2258. 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));
  2259. }
  2260. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2261. {
  2262. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2263. }
  2264. else
  2265. {
  2266. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2267. }
  2268. }
  2269. }
  2270. }
  2271. else
  2272. {
  2273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2274. {
  2275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2278. }
  2279. maxProfile.ChargingProfileId = -1;
  2280. maxProfile.StackLevel = -1;
  2281. if(maxProfile.ChargingProfileId == -1)
  2282. DEBUG_INFO("MaxProfile found.\n");
  2283. else
  2284. DEBUG_INFO("MaxProfile updated.\n");
  2285. // Required item
  2286. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2287. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2288. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2289. if(isUnitA)
  2290. {
  2291. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2292. 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++)
  2293. {
  2294. 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"));
  2295. 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?
  2296. 3:
  2297. 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")));
  2298. 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")));
  2299. }
  2300. }
  2301. else
  2302. {
  2303. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2304. 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++)
  2305. {
  2306. 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"));
  2307. 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?
  2308. 3:
  2309. 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")));
  2310. 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));
  2311. }
  2312. }
  2313. // Optional item
  2314. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2315. {
  2316. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2317. }
  2318. else
  2319. {
  2320. sprintf((char*)maxProfile.ValidFrom, " ");
  2321. }
  2322. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2323. {
  2324. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2325. }
  2326. else
  2327. {
  2328. sprintf((char*)maxProfile.ValidTo, " ");
  2329. }
  2330. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2331. {
  2332. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2333. }
  2334. else
  2335. {
  2336. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2337. }
  2338. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2339. {
  2340. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2341. }
  2342. else
  2343. {
  2344. maxProfile.TransactionId = -1;
  2345. }
  2346. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2347. {
  2348. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2349. }
  2350. else
  2351. {
  2352. maxProfile.ChargingSchedule.Duration = 86400;
  2353. }
  2354. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2355. {
  2356. 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")));
  2357. }
  2358. else
  2359. {
  2360. 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));
  2361. }
  2362. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2363. {
  2364. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2365. }
  2366. else
  2367. {
  2368. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2369. }
  2370. }
  2371. }
  2372. }
  2373. json_object_put(obj);
  2374. }
  2375. fclose(fp);
  2376. /*
  2377. if(maxProfile.ChargingProfileId !=-1)
  2378. {
  2379. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2380. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2381. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2382. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2383. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2384. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2385. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2386. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2387. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2388. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2389. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2390. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2391. {
  2392. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2393. {
  2394. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2395. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2396. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2397. }
  2398. }
  2399. }
  2400. else
  2401. DEBUG_INFO("MaxProfile not found.\n");
  2402. DEBUG_INFO("------------------------------------\n");*/
  2403. }
  2404. /*
  2405. * Align found profile start schedule & periods
  2406. */
  2407. //DEBUG_INFO("====================================\n");
  2408. /*
  2409. // For local test usage, force modify found profile start schedule info
  2410. 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);
  2411. 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);
  2412. 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);
  2413. */
  2414. if(txProfile.ChargingProfileId != -1)
  2415. {
  2416. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2417. {
  2418. if(txProfile.ChargingSchedule.Duration != -1)
  2419. {
  2420. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2421. 0:
  2422. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2423. }
  2424. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2425. {
  2426. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2427. {
  2428. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2429. 0:
  2430. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2431. if(idxPeriod > 0)
  2432. {
  2433. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2434. {
  2435. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2442. {
  2443. if(txProfile.ChargingSchedule.Duration != -1)
  2444. {
  2445. 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?
  2446. 0:
  2447. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2448. }
  2449. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2450. {
  2451. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2452. {
  2453. 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?
  2454. 0:
  2455. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2456. if(idxPeriod > 0)
  2457. {
  2458. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2459. {
  2460. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2461. }
  2462. }
  2463. }
  2464. }
  2465. }
  2466. else
  2467. {
  2468. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2469. {
  2470. if(txProfile.ChargingSchedule.Duration != -1)
  2471. {
  2472. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2473. 0:
  2474. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2475. }
  2476. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2477. {
  2478. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2479. {
  2480. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2481. 0:
  2482. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2483. if(idxPeriod > 0)
  2484. {
  2485. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2486. {
  2487. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2488. }
  2489. }
  2490. }
  2491. }
  2492. }
  2493. else
  2494. {
  2495. if(txProfile.ChargingSchedule.Duration != -1)
  2496. {
  2497. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2498. 0:
  2499. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2500. }
  2501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2502. {
  2503. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2504. {
  2505. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2506. 0:
  2507. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2508. if(idxPeriod > 0)
  2509. {
  2510. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2511. {
  2512. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. /*
  2520. DEBUG_INFO("txProfile after align.\n");
  2521. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2522. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2523. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2524. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2525. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2526. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2527. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2528. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2529. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2530. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2531. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2532. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2533. {
  2534. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2535. {
  2536. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2537. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2538. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2539. }
  2540. }*/
  2541. }
  2542. if(defaultTxProfile.ChargingProfileId != -1)
  2543. {
  2544. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2545. {
  2546. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2547. {
  2548. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2549. 0:
  2550. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2551. }
  2552. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2553. {
  2554. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2555. {
  2556. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2557. 0:
  2558. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2559. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2560. {
  2561. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2562. }
  2563. if(idxPeriod > 0)
  2564. {
  2565. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2566. {
  2567. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2568. }
  2569. }
  2570. }
  2571. }
  2572. }
  2573. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2574. {
  2575. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2576. {
  2577. 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?
  2578. 0:
  2579. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2580. }
  2581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2582. {
  2583. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2584. {
  2585. 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?
  2586. 0:
  2587. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2588. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2589. {
  2590. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2591. }
  2592. if(idxPeriod > 0)
  2593. {
  2594. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2595. {
  2596. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2597. }
  2598. }
  2599. }
  2600. }
  2601. }
  2602. else
  2603. {
  2604. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2605. {
  2606. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2607. {
  2608. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2609. 0:
  2610. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2611. }
  2612. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2613. {
  2614. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2615. {
  2616. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2617. 0:
  2618. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2619. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2620. {
  2621. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2622. }
  2623. if(idxPeriod > 0)
  2624. {
  2625. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2626. {
  2627. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2628. }
  2629. }
  2630. }
  2631. }
  2632. }
  2633. else
  2634. {
  2635. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2636. {
  2637. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2638. 0:
  2639. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2640. }
  2641. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2642. {
  2643. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2644. {
  2645. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2646. 0:
  2647. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2648. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2649. {
  2650. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2651. }
  2652. if(idxPeriod > 0)
  2653. {
  2654. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2655. {
  2656. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. /*
  2664. DEBUG_INFO("defaultTxProfile after align.\n");
  2665. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2666. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2667. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2668. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2669. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2670. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2671. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2672. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2673. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2674. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2675. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2677. {
  2678. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2679. {
  2680. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2681. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2682. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2683. }
  2684. }
  2685. DEBUG_INFO("------------------------------------\n");*/
  2686. }
  2687. if(maxProfile.ChargingProfileId != -1)
  2688. {
  2689. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2690. {
  2691. if(maxProfile.ChargingSchedule.Duration != -1)
  2692. {
  2693. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2694. 0:
  2695. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2696. }
  2697. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2698. {
  2699. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2700. {
  2701. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2702. 0:
  2703. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2704. if(idxPeriod > 0)
  2705. {
  2706. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2707. {
  2708. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2709. }
  2710. }
  2711. }
  2712. }
  2713. }
  2714. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2715. {
  2716. if(maxProfile.ChargingSchedule.Duration != -1)
  2717. {
  2718. 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?
  2719. 0:
  2720. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2721. }
  2722. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2723. {
  2724. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2725. {
  2726. 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?
  2727. 0:
  2728. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2729. if(idxPeriod > 0)
  2730. {
  2731. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2732. {
  2733. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2734. }
  2735. }
  2736. }
  2737. }
  2738. }
  2739. else
  2740. {
  2741. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2742. {
  2743. if(maxProfile.ChargingSchedule.Duration != -1)
  2744. {
  2745. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2746. 0:
  2747. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2748. }
  2749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2750. {
  2751. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2752. {
  2753. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2754. 0:
  2755. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2756. if(idxPeriod > 0)
  2757. {
  2758. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2759. {
  2760. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2761. }
  2762. }
  2763. }
  2764. }
  2765. }
  2766. else
  2767. {
  2768. if(maxProfile.ChargingSchedule.Duration != -1)
  2769. {
  2770. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2771. 0:
  2772. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2773. }
  2774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2775. {
  2776. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2777. {
  2778. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2779. 0:
  2780. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2781. if(idxPeriod > 0)
  2782. {
  2783. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2784. {
  2785. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2786. }
  2787. }
  2788. }
  2789. }
  2790. }
  2791. }
  2792. /*
  2793. DEBUG_INFO("MaxProfile after align.\n");
  2794. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2795. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2796. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2797. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2798. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2799. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2800. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2801. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2802. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2803. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2804. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2805. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2806. {
  2807. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2808. {
  2809. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2810. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2811. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2812. }
  2813. }
  2814. DEBUG_INFO("------------------------------------\n");*/
  2815. }
  2816. /*
  2817. * Merge to conposite schedule
  2818. */
  2819. //DEBUG_INFO("====================================\n");
  2820. // Find each profile period quantity
  2821. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2822. {
  2823. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2824. limitMax = idx+1;
  2825. }
  2826. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2827. {
  2828. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2829. limitDef = idx+1;
  2830. }
  2831. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2832. {
  2833. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2834. limitTx = idx+1;
  2835. }
  2836. // TxProfile found, composite schedule based on it
  2837. if(txProfile.ChargingProfileId != -1)
  2838. {
  2839. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2840. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2841. {
  2842. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2843. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2844. (txProfile.ChargingSchedule.Duration > 0))
  2845. {
  2846. if(maxProfile.ChargingProfileId != -1)
  2847. {
  2848. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2849. {
  2850. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2851. {
  2852. if((maxProfile.ChargingSchedule.Duration > 0))
  2853. {
  2854. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2855. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2856. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2857. }
  2858. else
  2859. {
  2860. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2861. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2862. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2863. }
  2864. }
  2865. if(idxMaxPeriod == (limitMax-1))
  2866. {
  2867. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2868. {
  2869. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2870. {
  2871. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2872. compositePeriodIdx++;
  2873. }
  2874. else
  2875. {
  2876. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. else
  2883. {
  2884. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2885. {
  2886. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2887. compositePeriodIdx++;
  2888. }
  2889. else
  2890. {
  2891. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2892. }
  2893. }
  2894. }
  2895. if(idxTxPeriod == (limitTx-1))
  2896. {
  2897. if(defaultTxProfile.ChargingProfileId != -1)
  2898. {
  2899. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  2900. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2901. {
  2902. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2903. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2904. (defaultTxProfile.ChargingSchedule.Duration>0))
  2905. {
  2906. if(maxProfile.ChargingProfileId != -1)
  2907. {
  2908. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2909. {
  2910. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2911. {
  2912. if((maxProfile.ChargingSchedule.Duration > 0))
  2913. {
  2914. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2915. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2916. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2917. }
  2918. else
  2919. {
  2920. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2921. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2922. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2923. }
  2924. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2925. {
  2926. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2927. {
  2928. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2929. compositePeriodIdx++;
  2930. }
  2931. else
  2932. {
  2933. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2934. }
  2935. }
  2936. // Delete duplicate period
  2937. if(compositePeriodIdx > 1)
  2938. {
  2939. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2940. {
  2941. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2942. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2943. compositePeriodIdx -= 1;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2950. {
  2951. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2952. compositePeriodIdx++;
  2953. }
  2954. else
  2955. {
  2956. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2957. }
  2958. break;
  2959. }
  2960. }
  2961. }
  2962. else
  2963. {
  2964. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2965. {
  2966. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2967. compositePeriodIdx++;
  2968. }
  2969. else
  2970. {
  2971. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2972. }
  2973. }
  2974. }
  2975. }
  2976. }
  2977. }
  2978. }
  2979. }
  2980. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2981. else if(defaultTxProfile.ChargingProfileId != -1)
  2982. {
  2983. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2984. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2985. {
  2986. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2987. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2988. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2989. {
  2990. if(maxProfile.ChargingProfileId != -1)
  2991. {
  2992. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2993. {
  2994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2995. {
  2996. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2997. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2998. if((maxProfile.ChargingSchedule.Duration > 0))
  2999. {
  3000. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3001. }
  3002. else
  3003. {
  3004. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3005. }
  3006. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3007. {
  3008. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3009. {
  3010. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3011. compositePeriodIdx++;
  3012. }
  3013. else
  3014. {
  3015. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3016. }
  3017. }
  3018. // Delete duplicate period
  3019. if(compositePeriodIdx > 1)
  3020. {
  3021. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3022. {
  3023. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3024. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3025. compositePeriodIdx -= 1;
  3026. }
  3027. }
  3028. }
  3029. else
  3030. {
  3031. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3032. {
  3033. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3034. compositePeriodIdx++;
  3035. }
  3036. else
  3037. {
  3038. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3039. }
  3040. break;
  3041. }
  3042. }
  3043. }
  3044. else
  3045. {
  3046. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3047. {
  3048. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3049. compositePeriodIdx++;
  3050. }
  3051. else
  3052. {
  3053. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3054. }
  3055. }
  3056. }
  3057. }
  3058. }
  3059. // Fill other period by MaxProfile
  3060. if(maxProfile.ChargingProfileId != -1)
  3061. {
  3062. if(compositePeriodIdx==0)
  3063. {
  3064. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3065. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3066. {
  3067. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3068. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3069. (maxProfile.ChargingSchedule.Duration > 0))
  3070. {
  3071. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3072. {
  3073. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3074. compositePeriodIdx++;
  3075. }
  3076. else
  3077. {
  3078. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3079. }
  3080. }
  3081. }
  3082. }
  3083. else
  3084. {
  3085. int lastCompositePeriodIdx = compositePeriodIdx;
  3086. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3087. {
  3088. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3089. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3090. (maxProfile.ChargingSchedule.Duration > 0))
  3091. {
  3092. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3095. {
  3096. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3097. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3098. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3099. }
  3100. else
  3101. {
  3102. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3103. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3104. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3105. }
  3106. }
  3107. if(tmpPeriod.Limit != -1)
  3108. {
  3109. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3110. {
  3111. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3112. {
  3113. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3114. compositePeriodIdx++;
  3115. }
  3116. else
  3117. {
  3118. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3119. }
  3120. }
  3121. // Delete duplicate period
  3122. if(compositePeriodIdx > 1)
  3123. {
  3124. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3125. {
  3126. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3127. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3128. compositePeriodIdx -= 1;
  3129. }
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. compositeProfile.ChargingSchedule.Duration = durationReq;
  3137. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3138. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3139. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3140. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3141. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3142. {
  3143. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3144. {
  3145. compositeProfile.ChargingProfileId = 1;
  3146. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3147. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3148. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3149. }
  3150. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3151. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3152. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3153. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3154. }
  3155. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3156. if(line)
  3157. free(line);
  3158. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3159. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3160. }
  3161. //==========================================
  3162. // Init all share memory
  3163. //==========================================
  3164. int InitShareMemory()
  3165. {
  3166. int result = PASS;
  3167. int MeterSMId;
  3168. //creat ShmSysConfigAndInfo
  3169. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3170. {
  3171. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3172. result = FAIL;
  3173. }
  3174. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3175. {
  3176. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3177. result = FAIL;
  3178. }
  3179. else
  3180. {}
  3181. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3182. {
  3183. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3184. result = FAIL;
  3185. }
  3186. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3187. {
  3188. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3189. result = FAIL;
  3190. }
  3191. else
  3192. {}
  3193. //creat ShmPsuData
  3194. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3195. {
  3196. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3197. result = FAIL;
  3198. }
  3199. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3200. {
  3201. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3202. result = FAIL;
  3203. }
  3204. else
  3205. {}
  3206. //link ShmOCPP16Data
  3207. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3208. {
  3209. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3210. result = FAIL;
  3211. }
  3212. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3213. {
  3214. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3215. result = FAIL;
  3216. }
  3217. else
  3218. {}
  3219. //creat ShmOCPP16DataPH
  3220. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3221. {
  3222. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3223. result = FAIL;
  3224. }
  3225. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3226. {
  3227. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3228. result = FAIL;
  3229. }
  3230. else
  3231. {}
  3232. /****************************** For Initial Settings************************************************/
  3233. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3234. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3235. // allocate Configuration memory address
  3236. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3237. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3238. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3239. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3240. //offline MeterValue Interval
  3241. TempMeterValueInterval = 0;
  3242. return result;
  3243. }
  3244. int ProcessShareMemory()
  3245. {
  3246. int result = PASS;
  3247. if(InitShareMemory() == FAIL)
  3248. {
  3249. DEBUG_ERROR("InitShareMemory NG\n");
  3250. if(ShmStatusCodeData!=NULL)
  3251. {
  3252. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3253. }
  3254. result = FAIL;
  3255. }
  3256. // Model name parsing
  3257. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3258. {
  3259. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3260. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3261. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3262. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3263. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3264. ) // 'D' means DC
  3265. {
  3266. // DO series
  3267. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3268. {
  3269. SystemInitial += 1;
  3270. gunTotalNumber += 1;
  3271. gunType[gun_index] = GUN_TYPE_DO;
  3272. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3273. {
  3274. case Gun_Type_Chademo:
  3275. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3276. break;
  3277. case Gun_Type_CCS_2:
  3278. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3279. break;
  3280. case Gun_Type_GB:
  3281. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3282. break;
  3283. case Gun_Type_AC:
  3284. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3285. break;
  3286. default:
  3287. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3288. break;
  3289. }
  3290. }
  3291. }
  3292. else
  3293. {
  3294. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3295. {
  3296. SystemInitial += 1;
  3297. gunTotalNumber += 1;
  3298. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3299. {
  3300. case Gun_Type_Chademo:
  3301. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3302. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3303. break;
  3304. case Gun_Type_CCS_2:
  3305. gunType[gun_index] = GUN_TYPE_CCS;
  3306. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3307. break;
  3308. case Gun_Type_GB:
  3309. gunType[gun_index] = GUN_TYPE_GBT;
  3310. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3311. break;
  3312. case Gun_Type_AC:
  3313. gunType[gun_index] = GUN_TYPE_AC;
  3314. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3315. break;
  3316. default:
  3317. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3318. break;
  3319. }
  3320. }
  3321. }
  3322. }
  3323. else
  3324. {
  3325. DEBUG_ERROR("Model name parsing fail.\n");
  3326. result = FAIL;
  3327. }
  3328. if(result != PASS)sleep(5);
  3329. return result;
  3330. }
  3331. void checkRemoteStart(uint8_t connectorIdInt)
  3332. {
  3333. uint8_t tempIndex;
  3334. int result = PASS;
  3335. char cmdBuf[512];
  3336. //check Transaction active
  3337. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3338. {
  3339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3340. {
  3341. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3342. }
  3343. else
  3344. {
  3345. tempIndex = connectorIdInt -1;
  3346. }
  3347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3348. {
  3349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3350. {
  3351. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3352. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3353. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3354. {
  3355. //Reserved
  3356. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3357. }
  3358. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3359. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3360. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3361. {
  3362. //Reserved
  3363. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3364. result = FAIL;
  3365. goto end;
  3366. }
  3367. else
  3368. {
  3369. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3370. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3371. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3372. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3373. {
  3374. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3375. result = FAIL;
  3376. goto end;
  3377. }
  3378. }//END FOR ELSE
  3379. }
  3380. }// END FOR CHAdeMO_QUANTITY
  3381. }
  3382. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3383. {
  3384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3385. {
  3386. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3387. }
  3388. else
  3389. {
  3390. tempIndex = connectorIdInt -1;
  3391. }
  3392. for (int index = 0; index < CCS_QUANTITY; index++)
  3393. {
  3394. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3395. {
  3396. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3397. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3398. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3399. {
  3400. //Reserved
  3401. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3402. }
  3403. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3404. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3405. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3406. {
  3407. //Reserved
  3408. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3409. result = FAIL;
  3410. goto end;
  3411. }
  3412. else
  3413. {
  3414. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3415. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3416. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3417. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3418. {
  3419. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3420. result = FAIL;
  3421. goto end;
  3422. }
  3423. }// END FOR ELSE
  3424. }
  3425. }// END FOR CCS_QUANTITY
  3426. }
  3427. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3428. {
  3429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3430. {
  3431. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3432. }
  3433. else
  3434. {
  3435. tempIndex = connectorIdInt -1;
  3436. }
  3437. for (int index = 0; index < GB_QUANTITY; index++)
  3438. {
  3439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3440. {
  3441. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3442. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3443. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3444. {
  3445. //Reserved
  3446. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3447. }
  3448. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3449. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3450. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3451. {
  3452. //Reserved
  3453. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3454. result = FAIL;
  3455. goto end;
  3456. }
  3457. else
  3458. {
  3459. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3460. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3461. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3462. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3463. {
  3464. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3465. result = FAIL;
  3466. goto end;
  3467. }
  3468. }// END FOR ELSE
  3469. }
  3470. } // END FOR GB_QUANTITY
  3471. }
  3472. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3473. {
  3474. tempIndex = connectorIdInt -1;
  3475. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3476. {
  3477. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3478. {
  3479. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3480. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3481. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3482. {
  3483. //Reserved
  3484. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3485. }
  3486. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3487. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3488. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3489. {
  3490. //Reserved
  3491. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3492. result = FAIL;
  3493. goto end;
  3494. }
  3495. else
  3496. {
  3497. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3498. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3499. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3500. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3501. {
  3502. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3503. result = FAIL;
  3504. goto end;
  3505. }
  3506. }// END FOR ELSE
  3507. }
  3508. } // END FOR GB_QUANTITY
  3509. }
  3510. else
  3511. {
  3512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3513. {
  3514. tempIndex = 2;
  3515. }
  3516. else
  3517. {
  3518. tempIndex = connectorIdInt -1;
  3519. }
  3520. for (int index = 0; index < AC_QUANTITY; index++)
  3521. {
  3522. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3523. {
  3524. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3525. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3526. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3527. {
  3528. //Reserved
  3529. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3530. }
  3531. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3532. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3533. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3534. {
  3535. //Reserved
  3536. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3537. result = FAIL;
  3538. goto end;
  3539. }
  3540. else
  3541. {
  3542. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3543. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3544. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3545. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3546. {
  3547. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3548. result = FAIL;
  3549. goto end;
  3550. }
  3551. }//END FOR ELSE
  3552. }
  3553. }// END FOR AC_QUANTITY
  3554. }
  3555. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3556. {
  3557. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3558. {
  3559. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3560. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3561. {
  3562. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3563. system(cmdBuf);
  3564. }
  3565. }
  3566. else
  3567. {
  3568. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3569. result = FAIL;
  3570. }
  3571. }
  3572. end:
  3573. if(result == PASS)
  3574. {
  3575. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3576. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3577. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3578. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3580. }
  3581. }
  3582. void CheckSystemValue(void)
  3583. {
  3584. char filenmae[100]={0};
  3585. char str[100]={0};
  3586. int tempIndex = 0;
  3587. //===============================
  3588. // send Heartbeat
  3589. //===============================
  3590. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3591. {
  3592. //parameter for test
  3593. sendHeartbeatRequest(0);
  3594. //==============================================
  3595. // Reset Waiting Time
  3596. //==============================================
  3597. HeartBeatWithNOResponse += 2;
  3598. }
  3599. //===============================
  3600. // Credit deduct report
  3601. //===============================
  3602. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3603. {
  3604. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3605. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3606. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3607. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3608. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3609. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3610. }
  3611. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3612. {
  3613. OCPP_query_deduct_info();
  3614. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3615. }
  3616. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3617. {
  3618. // ClockAlign MeterValue
  3619. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3620. {
  3621. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3624. {
  3625. tempIndex = ((gun_index==2) ? 1: 0);
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3632. {
  3633. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3634. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3635. {
  3636. reqClockAlignMeter[gun_index] = 1;
  3637. }
  3638. }// End for CHAdeMO
  3639. }
  3640. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3641. {
  3642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3643. {
  3644. tempIndex = ((gun_index==2) ? 1: 0);
  3645. }
  3646. else
  3647. {
  3648. tempIndex = gun_index;
  3649. }
  3650. for (int index = 0; index < CCS_QUANTITY; index++)
  3651. {
  3652. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3653. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3654. {
  3655. reqClockAlignMeter[gun_index] = 1;
  3656. }
  3657. } // End for CCS
  3658. }
  3659. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3660. {
  3661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3662. {
  3663. tempIndex = ((gun_index==2) ? 1: 0);
  3664. }
  3665. else
  3666. {
  3667. tempIndex = gun_index;
  3668. }
  3669. for (int index = 0; index < GB_QUANTITY; index++)
  3670. {
  3671. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3672. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3673. {
  3674. reqClockAlignMeter[gun_index] = 1;
  3675. }
  3676. }// End for GB
  3677. }
  3678. else if(gunType[gun_index] == GUN_TYPE_DO)
  3679. {
  3680. tempIndex = gun_index;
  3681. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3682. {
  3683. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3684. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3685. {
  3686. reqClockAlignMeter[gun_index] = 1;
  3687. }
  3688. }
  3689. }
  3690. else
  3691. {
  3692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3693. {
  3694. tempIndex = 2;
  3695. }
  3696. else
  3697. {
  3698. tempIndex = gun_index;
  3699. }
  3700. for (int index = 0; index < AC_QUANTITY; index++)
  3701. {
  3702. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3703. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3704. {
  3705. reqClockAlignMeter[gun_index] = 1;
  3706. }
  3707. }//End for AC
  3708. }
  3709. }
  3710. }
  3711. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3712. {
  3713. //==========================================
  3714. // Check remote start without connector id
  3715. //==========================================
  3716. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3717. {
  3718. int connectorIdInt = -1;
  3719. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3720. {
  3721. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3722. {
  3723. connectorIdInt = (gun_index+1);
  3724. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3725. checkRemoteStart(connectorIdInt);
  3726. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3727. break;
  3728. }
  3729. }
  3730. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3731. {
  3732. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3733. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3734. }
  3735. }
  3736. //==========================================
  3737. // csu trigger DataTransferReq
  3738. //==========================================
  3739. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3740. {
  3741. sendDataTransferRequest(gun_index);
  3742. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3743. }
  3744. //===============================
  3745. // CSU Trigger Authorize Request
  3746. //===============================
  3747. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3748. {
  3749. sendAuthorizeRequest(0);
  3750. authorizeRetryTimes = authorizeRetryTimes + 1;
  3751. if(authorizeRetryTimes < 3)
  3752. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3753. }
  3754. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3755. {
  3756. authorizeRetryTimes = 0;
  3757. SetOcppConnStatus(FALSE);
  3758. server_sign = FALSE;
  3759. }
  3760. 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))
  3761. {
  3762. sendAuthorizeRequest(0);
  3763. }
  3764. //==============================================
  3765. // Charger start transaction
  3766. //==============================================
  3767. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3768. {
  3769. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3770. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3771. sendStartTransactionRequest(gun_index);
  3772. refreshStartTimer(&clientTime.StartTransaction);
  3773. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3774. //storeTempStopTransaction(gun_index);
  3775. }
  3776. //==============================================
  3777. // Charger stop transaction
  3778. //==============================================
  3779. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3780. {
  3781. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3782. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3783. sendStopTransactionRequest(gun_index);
  3784. refreshStartTimer(&clientTime.StopTransaction);
  3785. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3786. }
  3787. //==============================================
  3788. // Charger status report
  3789. //==============================================
  3790. //--- Check Mode Change ---//
  3791. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3792. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3793. {
  3794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3795. {
  3796. tempIndex = ((gun_index==2) ? 1: 0);
  3797. }
  3798. else
  3799. {
  3800. tempIndex = gun_index;
  3801. }
  3802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3803. {
  3804. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3805. {
  3806. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3807. {
  3808. // Sent unplug message for California pricing logic
  3809. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3810. {
  3811. uint8_t ts[20];
  3812. getNowDatetime(ts);
  3813. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3814. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3815. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3816. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3817. }
  3818. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3819. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3820. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3821. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3822. {
  3823. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3824. if((access(filenmae,F_OK))!=-1)
  3825. {
  3826. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3827. sprintf(str,"rm -f %s",filenmae);
  3828. system(str);
  3829. }
  3830. }
  3831. }
  3832. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3833. #if 1 // for TempStopTransaction
  3834. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3835. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3836. {
  3837. checkTempStopTransaction(gun_index);
  3838. }
  3839. #endif
  3840. }
  3841. }
  3842. }
  3843. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3844. {
  3845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3846. {
  3847. tempIndex = ((gun_index==2) ? 1: 0);
  3848. }
  3849. else
  3850. {
  3851. tempIndex = gun_index;
  3852. }
  3853. for (int index = 0; index < CCS_QUANTITY; index++)
  3854. {
  3855. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3856. {
  3857. 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]*/ )
  3858. {
  3859. // Sent unplug message for California pricing logic
  3860. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3861. {
  3862. uint8_t ts[20];
  3863. getNowDatetime(ts);
  3864. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3865. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3866. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3867. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3868. }
  3869. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3870. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3871. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3872. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3873. {
  3874. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3875. if((access(filenmae,F_OK))!=-1)
  3876. {
  3877. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3878. sprintf(str,"rm -f %s",filenmae);
  3879. system(str);
  3880. }
  3881. }
  3882. }
  3883. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3884. #if 1 // for TempStopTransaction
  3885. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3886. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3887. {
  3888. checkTempStopTransaction(gun_index);
  3889. }
  3890. #endif
  3891. }
  3892. }
  3893. }
  3894. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3895. {
  3896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3897. {
  3898. tempIndex = ((gun_index==2) ? 1: 0);
  3899. }
  3900. else
  3901. {
  3902. tempIndex = gun_index;
  3903. }
  3904. for (int index = 0; index < GB_QUANTITY; index++)
  3905. {
  3906. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3907. {
  3908. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3909. {
  3910. // Sent unplug message for California pricing logic
  3911. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3912. {
  3913. uint8_t ts[20];
  3914. getNowDatetime(ts);
  3915. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3916. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3917. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3918. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3919. }
  3920. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3921. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3922. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3923. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3924. {
  3925. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3926. if((access(filenmae,F_OK))!=-1)
  3927. {
  3928. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3929. sprintf(str,"rm -f %s",filenmae);
  3930. system(str);
  3931. }
  3932. }
  3933. }
  3934. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3935. #if 1 // for TempStopTransaction
  3936. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3937. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3938. {
  3939. checkTempStopTransaction(gun_index);
  3940. }
  3941. #endif
  3942. }
  3943. }
  3944. }
  3945. else if(gunType[gun_index] == GUN_TYPE_DO)
  3946. {
  3947. tempIndex = gun_index;
  3948. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3949. {
  3950. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3951. {
  3952. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3953. {
  3954. // Sent unplug message for California pricing logic
  3955. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3956. {
  3957. uint8_t ts[20];
  3958. getNowDatetime(ts);
  3959. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3960. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3961. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3962. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3963. }
  3964. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3965. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3966. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3967. 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
  3968. {
  3969. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3970. if((access(filenmae,F_OK))!=-1)
  3971. {
  3972. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3973. sprintf(str,"rm -f %s",filenmae);
  3974. system(str);
  3975. }
  3976. }
  3977. }
  3978. 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);
  3979. #if 1 // for TempStopTransaction
  3980. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3981. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3982. {
  3983. checkTempStopTransaction(gun_index);
  3984. }
  3985. #endif
  3986. }
  3987. }
  3988. }
  3989. else
  3990. {
  3991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3992. {
  3993. tempIndex = 2;
  3994. }
  3995. else
  3996. {
  3997. tempIndex = gun_index;
  3998. }
  3999. for (int index = 0; index < AC_QUANTITY; index++)
  4000. {
  4001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4002. {
  4003. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4004. {
  4005. // Sent unplug message for California pricing logic
  4006. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4007. {
  4008. uint8_t ts[20];
  4009. getNowDatetime(ts);
  4010. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4011. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4012. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4013. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4014. }
  4015. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4016. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4017. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4018. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4019. {
  4020. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4021. if((access(filenmae,F_OK))!=-1)
  4022. {
  4023. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4024. sprintf(str,"rm -f %s",filenmae);
  4025. system(str);
  4026. }
  4027. }
  4028. }
  4029. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4030. #if 1 // for TempStopTransaction
  4031. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4032. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4033. {
  4034. checkTempStopTransaction(gun_index);
  4035. }
  4036. #endif
  4037. }
  4038. }// END
  4039. }
  4040. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4041. (
  4042. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4043. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4044. )
  4045. )
  4046. {
  4047. if(SystemInitial > 0)
  4048. SystemInitial -= 1;
  4049. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4050. sendStatusNotificationRequest(gun_index);
  4051. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4052. }
  4053. //==============================================
  4054. // TCCI reader status report
  4055. //==============================================
  4056. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4057. {
  4058. reportReaderStatus(gun_index);
  4059. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4060. }
  4061. //==============================================
  4062. // CSU Trigger Smart Charging Profile
  4063. //==============================================
  4064. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4065. {
  4066. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4067. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4068. }
  4069. //==============================================
  4070. // Meter report
  4071. //==============================================
  4072. // Trigger MeterValue
  4073. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4074. {
  4075. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4076. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4077. }
  4078. // Clock-aligned Meter value
  4079. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4080. {
  4081. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4082. reqClockAlignMeter[gun_index] = 0;
  4083. }
  4084. // Sample period MeterValue
  4085. 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))))
  4086. {
  4087. //check Transaction active
  4088. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4089. {
  4090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4091. {
  4092. tempIndex = ((gun_index==2) ? 1: 0);
  4093. }
  4094. else
  4095. {
  4096. tempIndex = gun_index;
  4097. }
  4098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4099. {
  4100. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4101. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4102. {
  4103. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4104. {
  4105. reqSampleMeter[gun_index] = 1;
  4106. }
  4107. }
  4108. }// End for CHAdeMO
  4109. }
  4110. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4111. {
  4112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4113. {
  4114. tempIndex = ((gun_index==2) ? 1: 0);
  4115. }
  4116. else
  4117. {
  4118. tempIndex = gun_index;
  4119. }
  4120. for (int index = 0; index < CCS_QUANTITY; index++)
  4121. {
  4122. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4123. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4126. {
  4127. reqSampleMeter[gun_index] = 1;
  4128. }
  4129. }
  4130. } // End for CCS
  4131. }
  4132. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4133. {
  4134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4135. {
  4136. tempIndex = ((gun_index==2) ? 1: 0);
  4137. }
  4138. else
  4139. {
  4140. tempIndex = gun_index;
  4141. }
  4142. for (int index = 0; index < GB_QUANTITY; index++)
  4143. {
  4144. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4145. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4146. {
  4147. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4148. {
  4149. reqSampleMeter[gun_index] = 1;
  4150. }
  4151. }
  4152. }// End for GB
  4153. }
  4154. else if(gunType[gun_index] == GUN_TYPE_DO)
  4155. {
  4156. tempIndex = gun_index;
  4157. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4158. {
  4159. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4160. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4161. {
  4162. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4163. {
  4164. reqSampleMeter[gun_index] = 1;
  4165. }
  4166. }
  4167. }
  4168. }
  4169. else
  4170. {
  4171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4172. {
  4173. tempIndex = 2;
  4174. }
  4175. else
  4176. {
  4177. tempIndex = gun_index;
  4178. }
  4179. for (int index = 0; index < AC_QUANTITY; index++)
  4180. {
  4181. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4182. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4183. {
  4184. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4185. {
  4186. reqSampleMeter[gun_index] = 1;
  4187. }
  4188. }
  4189. }//End for AC
  4190. }
  4191. if(reqSampleMeter[gun_index] == 1)
  4192. {
  4193. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4194. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4195. //storeTempStopTransaction(gun_index);
  4196. reqSampleMeter[gun_index] = 0;
  4197. }
  4198. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4199. }
  4200. //==============================================
  4201. // Check Connector reserved
  4202. //==============================================
  4203. //===============================
  4204. // Check if Reserve is expired
  4205. //===============================
  4206. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4207. {
  4208. double diff_t;
  4209. struct tm tp;
  4210. // current time
  4211. time_t t = time(NULL);
  4212. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4213. tp.tm_isdst = -1;
  4214. time_t utc = mktime(&tp);
  4215. diff_t = difftime(utc, t);
  4216. if(diff_t <= 0)
  4217. {
  4218. DEBUG_INFO("reserve expired.\n");
  4219. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4220. }
  4221. }//END OF Check if Reserve is expired
  4222. //==========================================
  4223. // csu trigger FirmwareStatusNotificationReq
  4224. //==========================================
  4225. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4226. {
  4227. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4228. }
  4229. //==========================================
  4230. // csu trigger DiagnosticsStatusNotificationReq
  4231. //==========================================
  4232. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4233. {
  4234. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4235. }
  4236. //==========================================
  4237. // csu trigger CancelReservationConf
  4238. //==========================================
  4239. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4240. {
  4241. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4242. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4243. }
  4244. //==========================================
  4245. // csu trigger ChangeAvailabilityConf
  4246. //==========================================
  4247. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4248. {
  4249. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4250. }
  4251. //==========================================
  4252. // csu trigger UnlockConnectorConf
  4253. //==========================================
  4254. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4255. {
  4256. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4257. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4258. }
  4259. //==========================================
  4260. // csu trigger ReserveNowConf
  4261. //==========================================
  4262. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4263. {
  4264. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4265. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4266. }
  4267. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4268. {
  4269. sendSignCertificateRequest();
  4270. }
  4271. }
  4272. }
  4273. //==========================================
  4274. // send request routine
  4275. //==========================================
  4276. int sendAuthorizeRequest(int gun_index)
  4277. {
  4278. mtrace();
  4279. int result = FAIL;
  4280. char message[100]={0};
  4281. char guid[37];
  4282. char tempdata[65]={0};
  4283. DEBUG_INFO("sendAuthorizeRequest...\n");
  4284. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4285. //Local Authorize
  4286. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4287. {
  4288. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4289. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4290. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4291. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4292. result = PASS;
  4293. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4294. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4295. authorizeRetryTimes = 0;
  4296. return result;
  4297. }
  4298. 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))||
  4299. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4300. {
  4301. // Query from cache
  4302. DEBUG_INFO("Authorize from cache.\n");
  4303. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4304. // Query from list
  4305. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4306. {
  4307. DEBUG_INFO("Authorize from list.\n");
  4308. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4309. }
  4310. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4311. {
  4312. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4313. {
  4314. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4315. }
  4316. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4317. {
  4318. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4319. }
  4320. if(!GetOcppConnStatus())
  4321. {
  4322. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4323. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4324. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4325. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4326. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4327. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4328. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4329. authorizeRetryTimes = 0;
  4330. return result;
  4331. }
  4332. }
  4333. else
  4334. {
  4335. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4336. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4337. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4338. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4339. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4340. else
  4341. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4342. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4343. result = PASS;
  4344. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4345. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4346. authorizeRetryTimes = 0;
  4347. return result;
  4348. }
  4349. }
  4350. //initialize struct Authorize
  4351. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4352. //get data from shared memory
  4353. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4354. random_uuid(guid);
  4355. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4356. LWS_Send(message);
  4357. sprintf(tempdata, "Authorize,%d", gun_index);
  4358. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4359. {
  4360. result = PASS;
  4361. DEBUG_INFO("Authorize mapItem pass\n");
  4362. }
  4363. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4364. return result;
  4365. }
  4366. int sendBootNotificationRequest(void)
  4367. {
  4368. mtrace();
  4369. int result = FAIL;
  4370. char message[500]={0}, payload[700]={0};
  4371. char guid[37]={0};
  4372. char tempdata[65]={0};
  4373. // Fill BootNotification fields
  4374. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4375. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4376. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4377. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4378. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4379. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4380. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4381. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4382. ShmOCPP16DataPH->ChargeBoxId
  4383. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4384. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4385. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4386. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4387. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4388. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4389. random_uuid(guid);
  4390. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4391. LWS_Send(message);
  4392. sprintf(tempdata, "BootNotification,0");
  4393. 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*/)
  4394. {
  4395. result = PASS;
  4396. }
  4397. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4398. strcpy(queuedata,message);
  4399. return result;
  4400. }
  4401. int sendDataTransferRequest(int gun_index)
  4402. {
  4403. mtrace();
  4404. char message[1000]={0};
  4405. char guid[37]={0};
  4406. char tempdata[65]={0};
  4407. int result = FAIL;
  4408. random_uuid(guid);
  4409. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4410. MESSAGE_TYPE_CALL,
  4411. guid,
  4412. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4413. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4414. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4415. LWS_Send(message);
  4416. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4417. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4418. {
  4419. result = PASS;
  4420. DEBUG_INFO("DataTransfer mapItem pass\n");
  4421. }
  4422. return result;
  4423. }
  4424. int sendDiagnosticsStatusNotificationRequest(char *status)
  4425. {
  4426. mtrace();
  4427. int result = FAIL;
  4428. char message[110]={0};
  4429. char guid[37]={0};
  4430. char tempdata[65]={0};
  4431. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4432. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4433. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4434. random_uuid(guid);
  4435. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4436. LWS_SendNow(message);
  4437. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4438. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4439. {
  4440. result = PASS;
  4441. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4442. }
  4443. //#ifdef SystemLogMessage
  4444. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4445. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4446. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4447. //#endif
  4448. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4449. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4450. //record status
  4451. if(strcmp(status,"Idle")==0)
  4452. {
  4453. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4454. }
  4455. else if(strcmp(status,"Uploaded")==0)
  4456. {
  4457. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4458. }
  4459. else if(strcmp(status,"UploadFailed")==0)
  4460. {
  4461. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4462. }
  4463. else if(strcmp(status,"Uploading")==0)
  4464. {
  4465. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4466. }
  4467. return result;
  4468. }
  4469. int sendFirmwareStatusNotificationRequest(char *status)
  4470. {
  4471. mtrace();
  4472. int result = FAIL;
  4473. char message[110]={0};
  4474. char guid[37]={0};
  4475. char tempdata[65]={0};
  4476. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4477. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4478. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4479. random_uuid(guid);
  4480. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4481. LWS_SendNow(message);
  4482. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4483. 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*/)
  4484. {
  4485. result = PASS;
  4486. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4487. }
  4488. //#ifdef SystemLogMessage
  4489. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4490. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4491. //#endif
  4492. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4493. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4494. //record status
  4495. if(strcmp(status,"Downloaded")==0)
  4496. {
  4497. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4498. }
  4499. else if(strcmp(status,"DownloadFailed")==0)
  4500. {
  4501. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4502. }
  4503. else if(strcmp(status,"Downloading")==0)
  4504. {
  4505. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4506. }
  4507. else if(strcmp(status,"Idle")==0)
  4508. {
  4509. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4510. }
  4511. else if(strcmp(status,"InstallationFailed")==0)
  4512. {
  4513. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4514. }
  4515. else if(strcmp(status,"Installing")==0)
  4516. {
  4517. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4518. }
  4519. else if(strcmp(status,"Installed")==0)
  4520. {
  4521. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4522. }
  4523. return result;
  4524. }
  4525. int sendHeartbeatRequest(int gun_index)
  4526. {
  4527. mtrace();
  4528. int result = FAIL;
  4529. char message[80]={0};
  4530. char guid[37]={0};
  4531. char tempdata[65]={0};
  4532. random_uuid(guid);
  4533. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4534. , MESSAGE_TYPE_CALL
  4535. , guid );
  4536. LWS_Send(message);
  4537. sprintf(tempdata, "Heartbeat,%d", 0);
  4538. 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*/)
  4539. {
  4540. result = PASS;
  4541. }
  4542. return result;
  4543. }
  4544. int sendStartTransactionRequest(int gun_index)
  4545. {
  4546. mtrace();
  4547. int result = FAIL;
  4548. char message[250]={0};
  4549. char guid[37]={0};
  4550. struct timeval tmnow;
  4551. struct tm *tm;
  4552. char buf[28];//, usec_buf[6];
  4553. char tempdata[65]={0};
  4554. int tempIndex = 0;
  4555. DEBUG_INFO("sendStartTransactionRequest...\n");
  4556. gettimeofday(&tmnow, NULL);
  4557. time_t t;
  4558. t = time(NULL);
  4559. /*UTC time and date*/
  4560. tm = gmtime(&t);
  4561. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4562. #if 0 // remove temporally
  4563. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4564. strcat(buf,".");
  4565. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4566. strcat(buf,usec_buf);
  4567. #endif
  4568. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4569. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4570. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4571. // clear StartTransaction Response
  4572. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4573. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4574. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4575. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4576. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4577. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4578. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4579. {
  4580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4581. {
  4582. tempIndex = ((gun_index==2) ? 1: 0);
  4583. }
  4584. else
  4585. {
  4586. tempIndex = gun_index;
  4587. }
  4588. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4589. {
  4590. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4591. {
  4592. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4593. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4594. }
  4595. }
  4596. }
  4597. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4598. {
  4599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4600. {
  4601. tempIndex = ((gun_index==2) ? 1: 0);
  4602. }
  4603. else
  4604. {
  4605. tempIndex = gun_index;
  4606. }
  4607. for (int index = 0; index < CCS_QUANTITY; index++)
  4608. {
  4609. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4610. {
  4611. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4612. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4613. }
  4614. }
  4615. }
  4616. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4617. {
  4618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4619. {
  4620. tempIndex = ((gun_index==2) ? 1: 0);
  4621. }
  4622. else
  4623. {
  4624. tempIndex = gun_index;
  4625. }
  4626. for (int index = 0; index < GB_QUANTITY; index++)
  4627. {
  4628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4629. {
  4630. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4631. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4632. }
  4633. }
  4634. }
  4635. else if(gunType[gun_index] == GUN_TYPE_DO)
  4636. {
  4637. tempIndex = gun_index;
  4638. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4639. {
  4640. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4641. {
  4642. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4643. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4644. }
  4645. }
  4646. }
  4647. else
  4648. {
  4649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4650. {
  4651. tempIndex = 2;
  4652. }
  4653. else
  4654. {
  4655. tempIndex = gun_index;
  4656. }
  4657. for (int index = 0; index < AC_QUANTITY; index++)
  4658. {
  4659. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4660. {
  4661. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4662. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4663. }
  4664. }
  4665. }
  4666. random_uuid(guid);
  4667. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4668. {
  4669. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4670. , gun_index +1
  4671. , MESSAGE_TYPE_CALL
  4672. , guid
  4673. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4674. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4675. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4676. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4677. }
  4678. else
  4679. {
  4680. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4681. , gun_index +1
  4682. , MESSAGE_TYPE_CALL
  4683. , guid
  4684. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4685. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4686. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4687. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4688. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4689. }
  4690. #if 1
  4691. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4692. 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*/)
  4693. {
  4694. result = PASS;
  4695. }
  4696. #endif
  4697. strcpy(queuedata, message);
  4698. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4699. OCPP_insert_transaction_msg(YES, queuedata);
  4700. return result;
  4701. }
  4702. int sendStatusNotificationRequest(int gun_index)
  4703. {
  4704. mtrace();
  4705. int result = FAIL;
  4706. char message[600]={0};
  4707. char guid[37];
  4708. int currentStatus = 0;
  4709. struct timeval tmnow;
  4710. struct tm *tm;
  4711. char buf[28];//, usec_buf[6];
  4712. char tempdata[65]={0};
  4713. int tempIndex = 0;
  4714. uint8_t isStateChanged = TRUE;
  4715. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4716. gettimeofday(&tmnow, NULL);
  4717. time_t t;
  4718. t = time(NULL);
  4719. /*UTC time and date*/
  4720. tm = gmtime(&t);
  4721. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4722. #if 0 // remove temporally
  4723. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4724. strcat(buf,".");
  4725. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4726. strcat(buf,usec_buf);
  4727. #endif
  4728. //printf("%s",buf);
  4729. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4730. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4731. // it's option
  4732. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4733. /*
  4734. enum _SYSTEM_STATUS
  4735. {
  4736. S_BOOTING = 0,
  4737. S_IDLE, = 1
  4738. S_AUTHORIZING, =2
  4739. S_REASSIGN_CHECK, =3
  4740. S_REASSIGN, =4
  4741. S_PRECHARGE, =5
  4742. S_PREPARING_FOR_EV, =6
  4743. S_PREPARING_FOR_EVSE, =7
  4744. S_CHARGING, =8
  4745. S_TERMINATING, =9
  4746. S_COMPLETE, =10
  4747. S_ALARM, =11
  4748. S_FAULT =12
  4749. }
  4750. */
  4751. //check Transaction active
  4752. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4753. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4754. {
  4755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4756. {
  4757. tempIndex = ((gun_index==2) ? 1: 0);
  4758. }
  4759. else
  4760. {
  4761. tempIndex = gun_index;
  4762. }
  4763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4764. {
  4765. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4766. {
  4767. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4768. {
  4769. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4770. {
  4771. currentStatus = Preparing; //OCPP Status: Preparing
  4772. }
  4773. else
  4774. {
  4775. currentStatus = Available; //OCPP Status: Available
  4776. }
  4777. }
  4778. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4779. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4780. ) //S_PRECHARGE
  4781. {
  4782. currentStatus = Preparing; //OCPP Status: Preparing
  4783. }
  4784. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4785. {
  4786. currentStatus = Charging; //OCPP Status: Charging
  4787. }
  4788. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4789. {
  4790. currentStatus = Finishing; //OCPP Status: Finishing
  4791. }
  4792. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4793. {
  4794. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4795. }
  4796. 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
  4797. {
  4798. currentStatus = Unavailable; //OCPP Status: Unavailable
  4799. }
  4800. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4801. {
  4802. currentStatus = Faulted; //OCPP Status: Faulted
  4803. }
  4804. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4805. {
  4806. currentStatus = Reserved; //OCPP Status: Reserved
  4807. }
  4808. } //end of the same index
  4809. }//end of for CHAdeMO_QUANTITY
  4810. }
  4811. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4812. {
  4813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4814. {
  4815. tempIndex = ((gun_index==2) ? 1: 0);
  4816. }
  4817. else
  4818. {
  4819. tempIndex = gun_index;
  4820. }
  4821. for (int index = 0; index < CCS_QUANTITY; index++)
  4822. {
  4823. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4824. {
  4825. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4826. {
  4827. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4828. {
  4829. currentStatus = Preparing; //OCPP Status: Preparing
  4830. }
  4831. else
  4832. {
  4833. currentStatus = Available; //OCPP Status: Available
  4834. }
  4835. }
  4836. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4837. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4838. ) //S_PRECHARGE
  4839. {
  4840. currentStatus = Preparing; //OCPP Status: Preparing
  4841. }
  4842. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4843. {
  4844. currentStatus = Charging; //OCPP Status: Charging
  4845. }
  4846. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4847. {
  4848. currentStatus = Finishing; //OCPP Status: Finishing
  4849. }
  4850. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4851. {
  4852. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4853. }
  4854. 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
  4855. {
  4856. currentStatus = Unavailable; //OCPP Status : Unavailable
  4857. }
  4858. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4859. {
  4860. currentStatus = Faulted; //OCPP Status: Faulted
  4861. }
  4862. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4863. {
  4864. currentStatus = Reserved; //OCPP Status: Reserved
  4865. }
  4866. } //end of the same index
  4867. } // end of for CCS_QUANTITY
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4872. {
  4873. tempIndex = ((gun_index==2) ? 1: 0);
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < GB_QUANTITY; index++)
  4880. {
  4881. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4882. {
  4883. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4884. {
  4885. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4886. {
  4887. currentStatus = Preparing; //OCPP Status: Preparing
  4888. }
  4889. else
  4890. {
  4891. currentStatus = Available; //OCPP Status: Available
  4892. }
  4893. }
  4894. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4895. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4896. ) //S_PRECHARGE
  4897. {
  4898. currentStatus = Preparing; //OCPP Status: Preparing
  4899. }
  4900. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4901. {
  4902. currentStatus = Charging; //OCPP Status: Charging
  4903. }
  4904. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4905. {
  4906. currentStatus = Finishing; //OCPP Status: Finishing
  4907. }
  4908. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4909. {
  4910. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4911. }
  4912. 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
  4913. {
  4914. currentStatus = Unavailable; //OCPP Status: Unavailable
  4915. }
  4916. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4917. {
  4918. currentStatus = Faulted; //OCPP Status: Faulted
  4919. }
  4920. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4921. {
  4922. currentStatus = Reserved; //OCPP Status: Reserved
  4923. }
  4924. } //end of the same index
  4925. } // end of for GB_QUANTITY
  4926. }
  4927. else if(gunType[gun_index] == GUN_TYPE_DO)
  4928. {
  4929. tempIndex = gun_index;
  4930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4931. {
  4932. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4933. {
  4934. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4935. {
  4936. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4937. {
  4938. currentStatus = Preparing; //OCPP Status: Preparing
  4939. }
  4940. else
  4941. {
  4942. currentStatus = Available; //OCPP Status: Available
  4943. }
  4944. }
  4945. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4946. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4947. ) //S_PRECHARGE
  4948. {
  4949. currentStatus = Preparing; //OCPP Status: Preparing
  4950. }
  4951. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4952. {
  4953. currentStatus = Charging; //OCPP Status: Charging
  4954. }
  4955. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4956. {
  4957. currentStatus = Finishing; //OCPP Status: Finishing
  4958. }
  4959. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4960. {
  4961. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4962. }
  4963. 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
  4964. {
  4965. currentStatus = Unavailable; //OCPP Status: Unavailable
  4966. }
  4967. 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
  4968. {
  4969. currentStatus = Faulted; //OCPP Status: Faulted
  4970. }
  4971. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4972. {
  4973. currentStatus = Reserved; //OCPP Status: Reserved
  4974. }
  4975. } //end of the same index
  4976. }
  4977. }
  4978. else
  4979. {
  4980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4981. {
  4982. tempIndex = 2;
  4983. }
  4984. else
  4985. {
  4986. tempIndex = gun_index;
  4987. }
  4988. for (int index = 0; index < AC_QUANTITY; index++)
  4989. {
  4990. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4991. {
  4992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4993. {
  4994. 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))
  4995. {
  4996. currentStatus = Preparing; //OCPP Status: Preparing
  4997. }
  4998. else
  4999. {
  5000. currentStatus = Available; //OCPP Status: Available
  5001. }
  5002. }
  5003. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5004. {
  5005. currentStatus = Preparing; //OCPP Status: Preparing
  5006. }
  5007. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5008. {
  5009. currentStatus = Charging; //OCPP Status: Charging
  5010. }
  5011. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5012. {
  5013. currentStatus = Finishing; //OCPP Status: Finishing
  5014. }
  5015. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5016. {
  5017. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5018. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5019. else
  5020. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5021. }
  5022. 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
  5023. {
  5024. currentStatus = Unavailable; //OCPP Status: Unavailable
  5025. }
  5026. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5027. {
  5028. currentStatus = Faulted; //OCPP Status: Faulted
  5029. }
  5030. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5031. {
  5032. currentStatus = Reserved; //OCPP Status: Reserved
  5033. }
  5034. }//end of the same index
  5035. }//end of for AC_QUANTITY
  5036. }
  5037. //it's option
  5038. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5039. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5040. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5041. {
  5042. isStateChanged = FALSE;
  5043. }
  5044. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5045. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5046. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5047. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5048. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5049. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5050. random_uuid(guid);
  5051. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5052. , MESSAGE_TYPE_CALL
  5053. , guid
  5054. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5055. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5056. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5057. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5058. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5059. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5060. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5061. if((server_sign == TRUE) && isStateChanged)
  5062. {
  5063. LWS_Send(message);
  5064. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5065. 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*/)
  5066. {
  5067. //DEBUG_ERROR("statusNotification mapitem pass");
  5068. result = PASS;
  5069. }
  5070. }
  5071. else
  5072. {
  5073. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5074. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5075. result = PASS;
  5076. }
  5077. return result;
  5078. }
  5079. int sendStopTransactionRequest(int gun_index)
  5080. {
  5081. mtrace();
  5082. int result = FAIL;
  5083. //char message[1500]={0};
  5084. char guid[37]={0};
  5085. char tempdata[65]={0};
  5086. int tempIndex = 0;
  5087. char TempStopTransaction[256];
  5088. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5089. //int idx_sample=0;
  5090. DEBUG_INFO("sendStopTransactionRequest \n");
  5091. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5092. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5093. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5096. {
  5097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5098. {
  5099. tempIndex = ((gun_index==2) ? 1: 0);
  5100. }
  5101. else
  5102. {
  5103. tempIndex = gun_index;
  5104. }
  5105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5108. {
  5109. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5110. }
  5111. }// END OF CHAdeMO_QUANTITY
  5112. }
  5113. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5114. {
  5115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5116. {
  5117. tempIndex = ((gun_index==2) ? 1: 0);
  5118. }
  5119. else
  5120. {
  5121. tempIndex = gun_index;
  5122. }
  5123. for (int index = 0; index < CCS_QUANTITY; index++)
  5124. {
  5125. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5126. {
  5127. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5128. }
  5129. }// END OF CCS_QUANTITY
  5130. }
  5131. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5132. {
  5133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5134. {
  5135. tempIndex = ((gun_index==2) ? 1: 0);
  5136. }
  5137. else
  5138. {
  5139. tempIndex = gun_index;
  5140. }
  5141. for (int index = 0; index < GB_QUANTITY; index++)
  5142. {
  5143. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5144. {
  5145. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5146. }
  5147. }// END OF GB_QUANTITY
  5148. }
  5149. else if(gunType[gun_index] == GUN_TYPE_DO)
  5150. {
  5151. tempIndex = gun_index;
  5152. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5153. {
  5154. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5155. {
  5156. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5157. }
  5158. }// END OF GB_QUANTITY
  5159. }
  5160. else
  5161. {
  5162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5163. {
  5164. tempIndex = 2;
  5165. }
  5166. else
  5167. {
  5168. tempIndex = gun_index;
  5169. }
  5170. for (int index = 0; index < AC_QUANTITY; index++)
  5171. {
  5172. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5173. {
  5174. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5175. }
  5176. }// END OF AC_QUANTITY
  5177. }
  5178. //====================================== Stop Transaction Time =====================================================
  5179. struct timeval tmnow;
  5180. struct tm *tm;
  5181. char buf[28];//, usec_buf[6];
  5182. gettimeofday(&tmnow, NULL);
  5183. time_t t;
  5184. t = time(NULL);
  5185. /*UTC time and date*/
  5186. tm = gmtime(&t);
  5187. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5188. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5189. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5190. random_uuid(guid);
  5191. /***********************************transactionData******************************************************/
  5192. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5193. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5194. //=================================
  5195. // Transaction_Begin
  5196. //=================================
  5197. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5198. {
  5199. //============================================ Energy.Active.Import.Interval ================================
  5200. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5203. 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*/]);
  5204. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5205. 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))
  5206. {
  5207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5208. }
  5209. else
  5210. {
  5211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5212. }
  5213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5215. }
  5216. //=================================
  5217. // Transaction_End
  5218. //=================================
  5219. // ================================= Current.Import L1 ===============================================
  5220. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5221. {
  5222. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5223. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5224. {
  5225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5226. {
  5227. tempIndex = ((gun_index==2) ? 1: 0);
  5228. }
  5229. else
  5230. {
  5231. tempIndex = gun_index;
  5232. }
  5233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5234. {
  5235. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5236. {
  5237. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5238. }
  5239. }// End of for CHAdeMO_QUANTITY
  5240. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5241. }
  5242. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5243. {
  5244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5245. {
  5246. tempIndex = ((gun_index==2) ? 1: 0);
  5247. }
  5248. else
  5249. {
  5250. tempIndex = gun_index;
  5251. }
  5252. for (int index = 0; index < CCS_QUANTITY; index++)
  5253. {
  5254. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5255. {
  5256. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5257. }
  5258. }// End of for CCS_QUANTITY
  5259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5260. }
  5261. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5262. {
  5263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5264. {
  5265. tempIndex = ((gun_index==2) ? 1: 0);
  5266. }
  5267. else
  5268. {
  5269. tempIndex = gun_index;
  5270. }
  5271. for (int index = 0; index < GB_QUANTITY; index++)
  5272. {
  5273. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5274. {
  5275. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5276. }
  5277. }// End of for GB_QUANTITY
  5278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5279. }
  5280. else if(gunType[gun_index] == GUN_TYPE_DO)
  5281. {
  5282. tempIndex = gun_index;
  5283. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5284. {
  5285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5286. {
  5287. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5288. }
  5289. }
  5290. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5291. }
  5292. else
  5293. {
  5294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5295. {
  5296. tempIndex = 2;
  5297. }
  5298. else
  5299. {
  5300. tempIndex = gun_index;
  5301. }
  5302. for (int index = 0; index < AC_QUANTITY; index++)
  5303. {
  5304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5305. {
  5306. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5307. }
  5308. }// End of for AC_QUANTITY
  5309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5310. }
  5311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5313. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5314. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5315. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5316. }
  5317. // ================================= Energy.Active.Import.Interval ==============================================
  5318. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5319. {
  5320. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5321. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5322. {
  5323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5324. {
  5325. tempIndex = ((gun_index==2) ? 1: 0);
  5326. }
  5327. else
  5328. {
  5329. tempIndex = gun_index;
  5330. }
  5331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5332. {
  5333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5334. {
  5335. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5336. }
  5337. }// END OF CHAdeMO_QUANTITY
  5338. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5339. }
  5340. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5341. {
  5342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5343. {
  5344. tempIndex = ((gun_index==2) ? 1: 0);
  5345. }
  5346. else
  5347. {
  5348. tempIndex = gun_index;
  5349. }
  5350. for (int index = 0; index < CCS_QUANTITY; index++)
  5351. {
  5352. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5353. {
  5354. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5355. }
  5356. }// END OF CCS_QUANTITY
  5357. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5358. }
  5359. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5360. {
  5361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5362. {
  5363. tempIndex = ((gun_index==2) ? 1: 0);
  5364. }
  5365. else
  5366. {
  5367. tempIndex = gun_index;
  5368. }
  5369. for (int index = 0; index < GB_QUANTITY; index++)
  5370. {
  5371. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5372. {
  5373. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5374. }
  5375. }// END OF GB_QUANTITY
  5376. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5377. }
  5378. else if(gunType[gun_index] == GUN_TYPE_DO)
  5379. {
  5380. tempIndex = gun_index;
  5381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5382. {
  5383. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5384. {
  5385. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5386. }
  5387. }
  5388. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5389. }
  5390. else
  5391. {
  5392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5393. {
  5394. tempIndex = 2;
  5395. }
  5396. else
  5397. {
  5398. tempIndex = gun_index;
  5399. }
  5400. for (int index = 0; index < AC_QUANTITY; index++)
  5401. {
  5402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5403. {
  5404. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5405. }
  5406. }// END OF AC_QUANTITY
  5407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5408. }
  5409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5412. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5413. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5414. }
  5415. //=================================== Power.Active.Import ==================================================
  5416. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5417. {
  5418. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5419. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5420. {
  5421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5422. {
  5423. tempIndex = ((gun_index==2) ? 1: 0);
  5424. }
  5425. else
  5426. {
  5427. tempIndex = gun_index;
  5428. }
  5429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5430. {
  5431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5432. {
  5433. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5434. }
  5435. } // End for CHAdeMO_QUANTITY
  5436. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5437. }
  5438. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5439. {
  5440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5441. {
  5442. tempIndex = ((gun_index==2) ? 1: 0);
  5443. }
  5444. else
  5445. {
  5446. tempIndex = gun_index;
  5447. }
  5448. for (int index = 0; index < CCS_QUANTITY; index++)
  5449. {
  5450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5451. {
  5452. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5453. }
  5454. } // END for CCS_QUANTITY
  5455. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5456. }
  5457. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5458. {
  5459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5460. {
  5461. tempIndex = ((gun_index==2) ? 1: 0);
  5462. }
  5463. else
  5464. {
  5465. tempIndex = gun_index;
  5466. }
  5467. for (int index = 0; index < GB_QUANTITY; index++)
  5468. {
  5469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5470. {
  5471. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5472. }
  5473. }// END for GB_QUANTITY
  5474. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5475. }
  5476. else if(gunType[gun_index] == GUN_TYPE_DO)
  5477. {
  5478. tempIndex = gun_index;
  5479. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5480. {
  5481. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5482. {
  5483. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5484. }
  5485. }
  5486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5487. }
  5488. else
  5489. {
  5490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5491. {
  5492. tempIndex = 2;
  5493. }
  5494. else
  5495. {
  5496. tempIndex = gun_index;
  5497. }
  5498. for (int index = 0; index < AC_QUANTITY; index++)
  5499. {
  5500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5501. {
  5502. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5503. }
  5504. } // END for AC_QUANTITY
  5505. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5506. }
  5507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5511. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5512. }
  5513. //============================ Voltage L1 ====================================
  5514. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5515. {
  5516. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5517. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5518. {
  5519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5520. {
  5521. tempIndex = ((gun_index==2) ? 1: 0);
  5522. }
  5523. else
  5524. {
  5525. tempIndex = gun_index;
  5526. }
  5527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5528. {
  5529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5530. {
  5531. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5532. }
  5533. } // END OF FOR CHAdeMO_QUANTITY
  5534. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5535. }
  5536. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5537. {
  5538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5539. {
  5540. tempIndex = ((gun_index==2) ? 1: 0);
  5541. }
  5542. else
  5543. {
  5544. tempIndex = gun_index;
  5545. }
  5546. for (int index = 0; index < CCS_QUANTITY; index++)
  5547. {
  5548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5549. {
  5550. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5551. }
  5552. } // END OF FOR CCS_QUANTITY
  5553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5554. }
  5555. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5556. {
  5557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5558. {
  5559. tempIndex = ((gun_index==2) ? 1: 0);
  5560. }
  5561. else
  5562. {
  5563. tempIndex = gun_index;
  5564. }
  5565. for (int index = 0; index < GB_QUANTITY; index++)
  5566. {
  5567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5568. {
  5569. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5570. }
  5571. } // END OF FOR GB_QUANTITY
  5572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5573. }
  5574. else if(gunType[gun_index] == GUN_TYPE_DO)
  5575. {
  5576. tempIndex = gun_index;
  5577. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5578. {
  5579. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5580. {
  5581. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5582. }
  5583. }
  5584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5585. }
  5586. else
  5587. {
  5588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5589. {
  5590. tempIndex = 2;
  5591. }
  5592. else
  5593. {
  5594. tempIndex = gun_index;
  5595. }
  5596. for (int index = 0; index < AC_QUANTITY; index++)
  5597. {
  5598. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5599. {
  5600. 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
  5601. }
  5602. } // END OF FOR AC_QUANTITY
  5603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5604. }
  5605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5610. }
  5611. //====================== End SoC ================================
  5612. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5613. {
  5614. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5615. 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))
  5616. {
  5617. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5618. {
  5619. tempIndex = ((gun_index==2) ? 1: 0);
  5620. }
  5621. else
  5622. {
  5623. tempIndex = gun_index;
  5624. }
  5625. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5626. {
  5627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5628. {
  5629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5630. {
  5631. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5632. }
  5633. }
  5634. }
  5635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5636. {
  5637. for (int index = 0; index < CCS_QUANTITY; index++)
  5638. {
  5639. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5640. {
  5641. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5642. }
  5643. }
  5644. }
  5645. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5646. {
  5647. for (int index = 0; index < GB_QUANTITY; index++)
  5648. {
  5649. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5650. {
  5651. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5652. }
  5653. }
  5654. }
  5655. else if(gunType[gun_index] == GUN_TYPE_DO)
  5656. {
  5657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5658. {
  5659. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5660. {
  5661. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5662. }
  5663. }
  5664. }
  5665. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5666. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5667. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5668. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5669. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5670. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5671. } // END FOR DC CASE
  5672. }
  5673. // ================================= Current.Import L2 ===============================================
  5674. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5675. {
  5676. // AC 3 phse L2 current
  5677. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5678. {
  5679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5680. {
  5681. tempIndex = 2;
  5682. }
  5683. else
  5684. {
  5685. tempIndex = gun_index;
  5686. }
  5687. for (int index = 0; index < AC_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5692. }
  5693. }// End of for AC_QUANTITY
  5694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5695. }
  5696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5697. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5701. }
  5702. // ================================= Current.Import L3 ===============================================
  5703. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5704. {
  5705. // AC 3 phse L3 current
  5706. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5707. {
  5708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5709. {
  5710. tempIndex = 2;
  5711. }
  5712. else
  5713. {
  5714. tempIndex = gun_index;
  5715. }
  5716. for (int index = 0; index < AC_QUANTITY; index++)
  5717. {
  5718. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5719. {
  5720. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5721. }
  5722. }// End of for AC_QUANTITY
  5723. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5724. }
  5725. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5727. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5730. }
  5731. //============================ Voltage L2 ====================================
  5732. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5733. {
  5734. // AC 3 phse L2 voltage
  5735. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5736. {
  5737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5738. {
  5739. tempIndex = 2;
  5740. }
  5741. else
  5742. {
  5743. tempIndex = gun_index;
  5744. }
  5745. for (int index = 0; index < AC_QUANTITY; index++)
  5746. {
  5747. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5748. {
  5749. 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
  5750. }
  5751. } // END OF FOR AC_QUANTITY
  5752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5753. }
  5754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5756. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5757. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5758. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5759. }
  5760. //============================ Voltage L3 ====================================
  5761. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5762. {
  5763. // AC 3 phse L3 voltage
  5764. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5765. {
  5766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5767. {
  5768. tempIndex = 2;
  5769. }
  5770. else
  5771. {
  5772. tempIndex = gun_index;
  5773. }
  5774. for (int index = 0; index < AC_QUANTITY; index++)
  5775. {
  5776. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5777. {
  5778. 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
  5779. }
  5780. } // END OF FOR AC_QUANTITY
  5781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5782. }
  5783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5786. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5787. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5788. }
  5789. //====================== Start SoC ================================
  5790. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5791. {
  5792. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5793. 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))
  5794. {
  5795. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5796. {
  5797. tempIndex = ((gun_index==2) ? 1: 0);
  5798. }
  5799. else
  5800. {
  5801. tempIndex = gun_index;
  5802. }
  5803. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5804. {
  5805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5806. {
  5807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5808. {
  5809. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5810. }
  5811. }
  5812. }
  5813. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5814. {
  5815. for (int index = 0; index < CCS_QUANTITY; index++)
  5816. {
  5817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5818. {
  5819. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5820. }
  5821. }
  5822. }
  5823. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5824. {
  5825. for (int index = 0; index < GB_QUANTITY; index++)
  5826. {
  5827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5828. {
  5829. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5830. }
  5831. }
  5832. }
  5833. else if(gunType[gun_index] == GUN_TYPE_DO)
  5834. {
  5835. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5836. {
  5837. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5838. {
  5839. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5840. }
  5841. }
  5842. }
  5843. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5848. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5849. } // END FOR DC CASE
  5850. }
  5851. //================================================ Message create ====================================================
  5852. json_object *StopTransaction = json_object_new_object();
  5853. json_object *transactionDatas = json_object_new_array();
  5854. json_object *sampledValues = json_object_new_array();
  5855. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5856. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5857. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5858. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5859. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5860. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5861. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5862. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5863. {
  5864. json_object *transactionData = json_object_new_object();
  5865. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5866. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5867. {
  5868. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5869. {
  5870. json_object *sampledValue = json_object_new_object();
  5871. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5872. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5873. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5874. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5875. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5876. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5877. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5878. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5879. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5880. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5881. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5882. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5883. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5884. json_object_array_add(sampledValues, sampledValue);
  5885. }
  5886. }
  5887. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5888. json_object_array_add(transactionDatas, transactionData);
  5889. }
  5890. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5891. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5892. ,MESSAGE_TYPE_CALL
  5893. ,guid
  5894. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5895. json_object_put(StopTransaction);
  5896. #if 1 // for TempStopTransaction
  5897. //Delete TempStopTransaction
  5898. if((access(TempStopTransaction,F_OK))!=-1)
  5899. {
  5900. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5901. }
  5902. #endif
  5903. #if 1
  5904. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5905. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5906. {
  5907. result = PASS;
  5908. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5909. }
  5910. #endif
  5911. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5912. OCPP_insert_transaction_msg(NO, queuedata);
  5913. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5914. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5915. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5916. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5917. {
  5918. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5919. }
  5920. //for test
  5921. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5922. return result;
  5923. }
  5924. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5925. {
  5926. mtrace();
  5927. int result = FAIL;
  5928. char guid[37]={0};
  5929. char tempdata[65]={0};
  5930. int tempIndex = 0;
  5931. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5932. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5933. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5934. //set value
  5935. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5936. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5937. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5938. -1);
  5939. random_uuid(guid);
  5940. //UTC Date time
  5941. struct timeval tmnow;
  5942. struct tm *tm;
  5943. char buf[28];//, usec_buf[6];
  5944. gettimeofday(&tmnow, NULL);
  5945. time_t t;
  5946. t = time(NULL);
  5947. /*UTC time and date*/
  5948. tm = gmtime(&t);
  5949. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5950. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5951. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5952. //********************************(1)Current.Import L1************************************************/
  5953. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5954. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5955. (dataType == ReadingContext_Trigger))
  5956. {
  5957. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5958. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5959. {
  5960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5961. {
  5962. tempIndex = ((gun_index==2) ? 1: 0);
  5963. }
  5964. else
  5965. {
  5966. tempIndex = gun_index;
  5967. }
  5968. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5969. {
  5970. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5971. {
  5972. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5973. }
  5974. }
  5975. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5976. }
  5977. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5978. {
  5979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5980. {
  5981. tempIndex = ((gun_index==2) ? 1: 0);
  5982. }
  5983. else
  5984. {
  5985. tempIndex = gun_index;
  5986. }
  5987. for (int index = 0; index < CCS_QUANTITY; index++)
  5988. {
  5989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5990. {
  5991. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5992. }
  5993. }
  5994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5995. }
  5996. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5997. {
  5998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5999. {
  6000. tempIndex = ((gun_index==2) ? 1: 0);
  6001. }
  6002. else
  6003. {
  6004. tempIndex = gun_index;
  6005. }
  6006. for (int index = 0; index < GB_QUANTITY; index++)
  6007. {
  6008. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6009. {
  6010. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6011. }
  6012. }
  6013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6014. }
  6015. else if(gunType[gun_index] == GUN_TYPE_DO)
  6016. {
  6017. tempIndex = gun_index;
  6018. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6019. {
  6020. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6021. {
  6022. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6023. }
  6024. }
  6025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6026. }
  6027. else
  6028. {
  6029. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6030. {
  6031. tempIndex = 2;
  6032. }
  6033. else
  6034. {
  6035. tempIndex = gun_index;
  6036. }
  6037. for (int index = 0; index < AC_QUANTITY; index++)
  6038. {
  6039. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6040. {
  6041. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6042. }
  6043. }
  6044. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6045. }
  6046. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6051. }
  6052. //********************************(2)Energy.Active.Import.Register ************************************************/
  6053. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6054. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6055. (dataType == ReadingContext_Trigger))
  6056. {
  6057. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6058. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6059. {
  6060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6061. {
  6062. tempIndex = ((gun_index==2) ? 1: 0);
  6063. }
  6064. else
  6065. {
  6066. tempIndex = gun_index;
  6067. }
  6068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6069. {
  6070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6071. {
  6072. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6073. }
  6074. }
  6075. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6076. }
  6077. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6078. {
  6079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6080. {
  6081. tempIndex = ((gun_index==2) ? 1: 0);
  6082. }
  6083. else
  6084. {
  6085. tempIndex = gun_index;
  6086. }
  6087. for (int index = 0; index < CCS_QUANTITY; index++)
  6088. {
  6089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6090. {
  6091. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6092. }
  6093. }
  6094. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6095. }
  6096. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6097. {
  6098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6099. {
  6100. tempIndex = ((gun_index==2) ? 1: 0);
  6101. }
  6102. else
  6103. {
  6104. tempIndex = gun_index;
  6105. }
  6106. for (int index = 0; index < GB_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6109. {
  6110. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6111. }
  6112. }
  6113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6114. }
  6115. else if(gunType[gun_index] == GUN_TYPE_DO)
  6116. {
  6117. tempIndex = gun_index;
  6118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6119. {
  6120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6121. {
  6122. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6123. }
  6124. }
  6125. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6126. }
  6127. else
  6128. {
  6129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6130. {
  6131. tempIndex = 2;
  6132. }
  6133. else
  6134. {
  6135. tempIndex = gun_index;
  6136. }
  6137. for (int index = 0; index < AC_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6140. {
  6141. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6142. }
  6143. }
  6144. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6145. }
  6146. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6148. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6149. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6150. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6151. }
  6152. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6153. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6154. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6155. (dataType == ReadingContext_Trigger))
  6156. {
  6157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6159. {
  6160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6161. {
  6162. tempIndex = ((gun_index==2) ? 1: 0);
  6163. }
  6164. else
  6165. {
  6166. tempIndex = gun_index;
  6167. }
  6168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6169. {
  6170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6171. {
  6172. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6173. }
  6174. } // END OF FOR CHAdeMO_QUANTITY
  6175. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6176. }
  6177. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6178. {
  6179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6180. {
  6181. tempIndex = ((gun_index==2) ? 1: 0);
  6182. }
  6183. else
  6184. {
  6185. tempIndex = gun_index;
  6186. }
  6187. for (int index = 0; index < CCS_QUANTITY; index++)
  6188. {
  6189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6190. {
  6191. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6192. }
  6193. } // END OF CCS_QUANTITY
  6194. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6195. }
  6196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6197. {
  6198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6199. {
  6200. tempIndex = ((gun_index==2) ? 1: 0);
  6201. }
  6202. else
  6203. {
  6204. tempIndex = gun_index;
  6205. }
  6206. for (int index = 0; index < GB_QUANTITY; index++)
  6207. {
  6208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6209. {
  6210. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6211. }
  6212. } // END OF GB_QUANTITY
  6213. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6214. }
  6215. else if(gunType[gun_index] == GUN_TYPE_DO)
  6216. {
  6217. tempIndex = gun_index;
  6218. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6221. {
  6222. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6223. }
  6224. }
  6225. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6226. }
  6227. else
  6228. {
  6229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6230. {
  6231. tempIndex = 2;
  6232. }
  6233. else
  6234. {
  6235. tempIndex = gun_index;
  6236. }
  6237. for (int index = 0; index < AC_QUANTITY; index++)
  6238. {
  6239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6240. {
  6241. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6242. }
  6243. }
  6244. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6245. }
  6246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6250. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6251. }
  6252. //********************************(4)Power.Active.Import************************************************/
  6253. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6254. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6255. (dataType == ReadingContext_Trigger))
  6256. {
  6257. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6258. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6259. {
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6261. {
  6262. tempIndex = ((gun_index==2) ? 1: 0);
  6263. }
  6264. else
  6265. {
  6266. tempIndex = gun_index;
  6267. }
  6268. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6269. {
  6270. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6271. {
  6272. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6273. }
  6274. } // END OF FOR
  6275. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6276. }
  6277. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6278. {
  6279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6280. {
  6281. tempIndex = ((gun_index==2) ? 1: 0);
  6282. }
  6283. else
  6284. {
  6285. tempIndex = gun_index;
  6286. }
  6287. for (int index = 0; index < CCS_QUANTITY; index++)
  6288. {
  6289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6290. {
  6291. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6292. }
  6293. }
  6294. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6295. }
  6296. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6297. {
  6298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6299. {
  6300. tempIndex = ((gun_index==2) ? 1: 0);
  6301. }
  6302. else
  6303. {
  6304. tempIndex = gun_index;
  6305. }
  6306. for (int index = 0; index < GB_QUANTITY; index++)
  6307. {
  6308. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6309. {
  6310. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6311. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6312. }
  6313. }
  6314. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6315. }
  6316. else if(gunType[gun_index] == GUN_TYPE_DO)
  6317. {
  6318. tempIndex = gun_index;
  6319. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6320. {
  6321. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6322. {
  6323. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6324. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6325. }
  6326. }
  6327. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6328. }
  6329. else
  6330. {
  6331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6332. {
  6333. tempIndex = 2;
  6334. }
  6335. else
  6336. {
  6337. tempIndex = gun_index;
  6338. }
  6339. for (int index = 0; index < AC_QUANTITY; index++)
  6340. {
  6341. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6342. {
  6343. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6344. }
  6345. }
  6346. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6347. }
  6348. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6352. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6353. }
  6354. //***********************************************(5)VOLTAGE L1******************************************************/
  6355. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6356. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6357. (dataType == ReadingContext_Trigger))
  6358. {
  6359. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  6371. {
  6372. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6373. {
  6374. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6375. }
  6376. }
  6377. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6378. }
  6379. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6394. }
  6395. }
  6396. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6397. }
  6398. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6399. {
  6400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6401. {
  6402. tempIndex = ((gun_index==2) ? 1: 0);
  6403. }
  6404. else
  6405. {
  6406. tempIndex = gun_index;
  6407. }
  6408. for (int index = 0; index < GB_QUANTITY; index++)
  6409. {
  6410. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6411. {
  6412. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6413. }
  6414. }
  6415. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6416. }
  6417. else if(gunType[gun_index] == GUN_TYPE_DO)
  6418. {
  6419. tempIndex = gun_index;
  6420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6421. {
  6422. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6423. {
  6424. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6425. }
  6426. }
  6427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6428. }
  6429. else
  6430. {
  6431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6432. {
  6433. tempIndex = 2;
  6434. }
  6435. else
  6436. {
  6437. tempIndex = gun_index;
  6438. }
  6439. for (int index = 0; index < AC_QUANTITY; index++)
  6440. {
  6441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6442. {
  6443. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6444. }
  6445. }
  6446. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6447. }
  6448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6453. }
  6454. //***********************************************(6)SOC******************************************************/
  6455. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6456. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6457. (dataType == ReadingContext_Trigger))
  6458. {
  6459. 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))
  6460. {
  6461. //idx_sample=5;
  6462. //sampledValue = NULL;
  6463. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6464. {
  6465. tempIndex = ((gun_index==2) ? 1: 0);
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6472. {
  6473. //tempIndex = ((gun_index==2) ? 1: 0);
  6474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6477. {
  6478. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6479. }
  6480. }
  6481. }
  6482. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6483. {
  6484. //tempIndex = ((gun_index==2) ? 1: 0);
  6485. for (int index = 0; index < CCS_QUANTITY; index++)
  6486. {
  6487. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6488. {
  6489. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6490. }
  6491. }
  6492. }
  6493. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6494. {
  6495. //tempIndex = ((gun_index==2) ? 1: 0);
  6496. for (int index = 0; index < GB_QUANTITY; index++)
  6497. {
  6498. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6499. {
  6500. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6501. }
  6502. }
  6503. }
  6504. else if(gunType[gun_index] == GUN_TYPE_DO)
  6505. {
  6506. //tempIndex = ((gun_index==2) ? 1: 0);
  6507. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6508. {
  6509. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6510. {
  6511. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6512. }
  6513. }
  6514. }
  6515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6518. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6519. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6520. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6521. }
  6522. }
  6523. //********************************(7)Current.Import L2************************************************/
  6524. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6525. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6526. (dataType == ReadingContext_Trigger))
  6527. {
  6528. // Only for AC 3 phase
  6529. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6530. {
  6531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6532. {
  6533. tempIndex = 2;
  6534. }
  6535. else
  6536. {
  6537. tempIndex = gun_index;
  6538. }
  6539. for (int index = 0; index < AC_QUANTITY; index++)
  6540. {
  6541. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6542. {
  6543. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6544. }
  6545. }
  6546. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6547. }
  6548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6549. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6550. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6551. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6552. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6553. }
  6554. //********************************(8)Current.Import L3************************************************/
  6555. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6556. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6557. (dataType == ReadingContext_Trigger))
  6558. {
  6559. // Only for AC 3 phase
  6560. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6561. {
  6562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6563. {
  6564. tempIndex = 2;
  6565. }
  6566. else
  6567. {
  6568. tempIndex = gun_index;
  6569. }
  6570. for (int index = 0; index < AC_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6573. {
  6574. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6575. }
  6576. }
  6577. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6578. }
  6579. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6580. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6581. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6582. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6583. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6584. }
  6585. //***********************************************(9)VOLTAGE L2******************************************************/
  6586. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6587. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6588. (dataType == ReadingContext_Trigger))
  6589. {
  6590. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6591. {
  6592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6593. {
  6594. tempIndex = 2;
  6595. }
  6596. else
  6597. {
  6598. tempIndex = gun_index;
  6599. }
  6600. for (int index = 0; index < AC_QUANTITY; index++)
  6601. {
  6602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6603. {
  6604. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6605. }
  6606. }
  6607. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6608. }
  6609. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6610. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6611. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6612. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6613. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6614. }
  6615. //***********************************************(10)VOLTAGE L3******************************************************/
  6616. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6617. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6618. (dataType == ReadingContext_Trigger))
  6619. {
  6620. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6621. {
  6622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6623. {
  6624. tempIndex = 2;
  6625. }
  6626. else
  6627. {
  6628. tempIndex = gun_index;
  6629. }
  6630. for (int index = 0; index < AC_QUANTITY; index++)
  6631. {
  6632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6633. {
  6634. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6635. }
  6636. }
  6637. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6638. }
  6639. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6640. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6641. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6642. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6643. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6644. }
  6645. //***********************************************(11)Current.Offered******************************************************/
  6646. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6647. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6648. (dataType == ReadingContext_Trigger))
  6649. {
  6650. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6651. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6652. {
  6653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6654. {
  6655. tempIndex = ((gun_index==2) ? 1: 0);
  6656. }
  6657. else
  6658. {
  6659. tempIndex = gun_index;
  6660. }
  6661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6662. {
  6663. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6664. {
  6665. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6666. }
  6667. } // END OF FOR CHAdeMO_QUANTITY
  6668. }
  6669. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6670. {
  6671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6672. {
  6673. tempIndex = ((gun_index==2) ? 1: 0);
  6674. }
  6675. else
  6676. {
  6677. tempIndex = gun_index;
  6678. }
  6679. for (int index = 0; index < CCS_QUANTITY; index++)
  6680. {
  6681. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6682. {
  6683. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6684. }
  6685. } // END OF CCS_QUANTITY
  6686. }
  6687. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6688. {
  6689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6690. {
  6691. tempIndex = ((gun_index==2) ? 1: 0);
  6692. }
  6693. else
  6694. {
  6695. tempIndex = gun_index;
  6696. }
  6697. for (int index = 0; index < GB_QUANTITY; index++)
  6698. {
  6699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6700. {
  6701. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6702. }
  6703. } // END OF GB_QUANTITY
  6704. }
  6705. else if(gunType[gun_index] == GUN_TYPE_DO)
  6706. {
  6707. tempIndex = gun_index;
  6708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6709. {
  6710. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6711. {
  6712. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6713. }
  6714. }
  6715. }
  6716. else
  6717. {
  6718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6719. {
  6720. tempIndex = 2;
  6721. }
  6722. else
  6723. {
  6724. tempIndex = gun_index;
  6725. }
  6726. for (int index = 0; index < AC_QUANTITY; index++)
  6727. {
  6728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6729. {
  6730. uint16_t currentOffer;
  6731. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6732. {
  6733. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6734. }
  6735. else
  6736. {
  6737. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6738. }
  6739. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6740. }
  6741. }
  6742. }
  6743. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6744. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6745. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6746. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6747. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6748. }
  6749. //***********************************************(12)Power.Offered******************************************************/
  6750. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6751. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6752. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6753. {
  6754. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6755. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6756. {
  6757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6758. {
  6759. tempIndex = ((gun_index==2) ? 1: 0);
  6760. }
  6761. else
  6762. {
  6763. tempIndex = gun_index;
  6764. }
  6765. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6766. {
  6767. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6768. {
  6769. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6770. }
  6771. } // END OF FOR CHAdeMO_QUANTITY
  6772. }
  6773. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6774. {
  6775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6776. {
  6777. tempIndex = ((gun_index==2) ? 1: 0);
  6778. }
  6779. else
  6780. {
  6781. tempIndex = gun_index;
  6782. }
  6783. for (int index = 0; index < CCS_QUANTITY; index++)
  6784. {
  6785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6786. {
  6787. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6788. }
  6789. } // END OF CCS_QUANTITY
  6790. }
  6791. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6792. {
  6793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6794. {
  6795. tempIndex = ((gun_index==2) ? 1: 0);
  6796. }
  6797. else
  6798. {
  6799. tempIndex = gun_index;
  6800. }
  6801. for (int index = 0; index < GB_QUANTITY; index++)
  6802. {
  6803. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6804. {
  6805. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6806. }
  6807. } // END OF GB_QUANTITY
  6808. }
  6809. else if(gunType[gun_index] == GUN_TYPE_DO)
  6810. {
  6811. tempIndex = gun_index;
  6812. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6813. {
  6814. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6815. {
  6816. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6817. }
  6818. }
  6819. }
  6820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6823. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6825. }
  6826. // Message create ====================================================================================================
  6827. if(TRUE)
  6828. {
  6829. json_object *MeterValueReq = json_object_new_object();
  6830. json_object *MeterValues = json_object_new_array();
  6831. json_object *sampledValues = json_object_new_array();
  6832. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6833. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6834. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6835. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6836. {
  6837. json_object *MeterValue = json_object_new_object();
  6838. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6839. {
  6840. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6841. {
  6842. json_object *sampledValue = json_object_new_object();
  6843. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6844. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6845. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6846. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6847. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6848. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6849. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6850. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6851. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6852. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6853. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6854. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6855. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6856. json_object_array_add(sampledValues, sampledValue);
  6857. }
  6858. }
  6859. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6860. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6861. json_object_array_add(MeterValues, MeterValue);
  6862. }
  6863. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6864. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6865. ,gun_index + 1
  6866. ,MESSAGE_TYPE_CALL
  6867. ,guid
  6868. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6869. json_object_put(MeterValueReq);
  6870. }
  6871. // Put request guid to hash map
  6872. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6873. 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*/)
  6874. {
  6875. result = PASS;
  6876. //DEBUG_INFO("MeterValues mapitem pass\n");
  6877. }
  6878. if((dataType != ReadingContext_Trigger) &&
  6879. (dataType != ReadingContext_Sample_Clock) &&
  6880. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6881. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6882. else
  6883. {
  6884. if(FirstHeartBeat)
  6885. LWS_Send(queuedata +2);
  6886. }
  6887. return result;
  6888. }
  6889. int sendLogStatusNotificationRequest(char *status)
  6890. {
  6891. mtrace();
  6892. int result = PASS;
  6893. char message[4096]={0};
  6894. char guid[37]={0};
  6895. char tempdata[128]={0};
  6896. json_object *LogStatusNotification = json_object_new_object();
  6897. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6898. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6899. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6900. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6901. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6902. random_uuid(guid);
  6903. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6904. json_object_put(LogStatusNotification);
  6905. LWS_Send(message);
  6906. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6907. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6908. {
  6909. result = PASS;
  6910. }
  6911. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6912. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6913. return result;
  6914. }
  6915. int sendSecurityEventNotificationRequest()
  6916. {
  6917. mtrace();
  6918. int result = PASS;
  6919. char message[4096]={0};
  6920. char guid[37]={0};
  6921. char tempdata[128]={0};
  6922. json_object *SecurityEventNotification = json_object_new_object();
  6923. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6924. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6925. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6926. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6927. random_uuid(guid);
  6928. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6929. json_object_put(SecurityEventNotification);
  6930. LWS_Send(message);
  6931. sprintf(tempdata, "SecurityEventNotification,0");
  6932. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6933. {
  6934. result = PASS;
  6935. }
  6936. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6937. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6938. return result;
  6939. }
  6940. int sendSignCertificateRequest()
  6941. {
  6942. mtrace();
  6943. int result = PASS;
  6944. char message[4096]={0};
  6945. char guid[37]={0};
  6946. char tempdata[128]={0};
  6947. json_object *SignCertificate = json_object_new_object();
  6948. DEBUG_INFO("sendSignCertificateRequest...\n");
  6949. // Read csr file content
  6950. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6951. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6952. char *line = NULL;
  6953. size_t len = 0;
  6954. while(getline(&line, &len, fp) != -1)
  6955. {
  6956. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6957. {
  6958. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6959. }
  6960. }
  6961. fclose(fp);
  6962. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6963. random_uuid(guid);
  6964. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6965. json_object_put(SignCertificate);
  6966. LWS_Send(message);
  6967. sprintf(tempdata, "SignCertificate,0");
  6968. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6969. {
  6970. result = PASS;
  6971. }
  6972. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6973. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6974. return result;
  6975. }
  6976. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6977. {
  6978. mtrace();
  6979. int result = PASS;
  6980. char message[110]={0};
  6981. char guid[37]={0};
  6982. char tempdata[65]={0};
  6983. json_object *FirmwareStatusNotification = json_object_new_object();
  6984. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6985. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6986. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6987. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6988. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6989. random_uuid(guid);
  6990. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6991. json_object_put(FirmwareStatusNotification);
  6992. LWS_Send(message);
  6993. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6994. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6995. {
  6996. result = PASS;
  6997. }
  6998. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6999. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7000. return result;
  7001. }
  7002. //==========================================
  7003. // send confirm routine
  7004. //==========================================
  7005. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7006. {
  7007. mtrace();
  7008. int result = FAIL;
  7009. char message[100]={0};
  7010. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7011. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7012. LWS_Send(message);
  7013. result = TRUE;
  7014. return result;
  7015. }
  7016. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7017. {
  7018. mtrace();
  7019. int result = FAIL;
  7020. char message[100]={0};
  7021. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7023. LWS_Send(message);
  7024. result = TRUE;
  7025. return result;
  7026. }
  7027. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7028. {
  7029. mtrace();
  7030. int result = FAIL;
  7031. char message[100]={0};
  7032. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7033. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7034. LWS_Send(message);
  7035. result = TRUE;
  7036. return result;
  7037. }
  7038. int sendClearCacheConfirmation(char *uuid,char *payload)
  7039. {
  7040. mtrace();
  7041. int result = FAIL;
  7042. char message[500]={0};
  7043. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7044. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7045. LWS_Send(message);
  7046. return result;
  7047. }
  7048. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7049. {
  7050. mtrace();
  7051. int result = FAIL;
  7052. char message[500]={0};
  7053. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7054. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7055. LWS_Send(message);
  7056. return result;
  7057. }
  7058. int sendDataTransferConfirmation(char *uuid,char *payload)
  7059. {
  7060. mtrace();
  7061. char statusStr[20]={0};
  7062. char dataStr[10]={0};
  7063. char sstr[20]={0};
  7064. int c = 0;
  7065. char *loc;
  7066. int result = FAIL;
  7067. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7068. /**********************status**************************/
  7069. loc = strstr(payload, "status");
  7070. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7071. c = 0;
  7072. while (loc[3+strlen("status")+c] != '\"')
  7073. {
  7074. sstr[c] = loc[3+strlen("status")+c];
  7075. c++;
  7076. }
  7077. sstr[c] = '\0';
  7078. strcpy(statusStr, sstr);
  7079. /**********************data**************************/
  7080. loc = strstr(payload, "data");
  7081. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7082. c = 0;
  7083. while (loc[3+strlen("data")+c] != '\"')
  7084. {
  7085. sstr[c] = loc[3+strlen("data")+c];
  7086. c++;
  7087. }
  7088. sstr[c] = '\0';
  7089. strcpy(dataStr, sstr);
  7090. return result;
  7091. }
  7092. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7093. {
  7094. mtrace();
  7095. int result = FAIL;
  7096. char message[1000]={0};
  7097. int CompositeScheduleIndex = 0;
  7098. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7099. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7100. if(nPeriod == 0)
  7101. {
  7102. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7103. {
  7104. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7105. ,MESSAGE_TYPE_CALLRESULT
  7106. ,uuid
  7107. ,payload
  7108. ,connectorIdInt);
  7109. }
  7110. else
  7111. {
  7112. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7113. ,MESSAGE_TYPE_CALLRESULT
  7114. ,uuid
  7115. ,payload
  7116. ,connectorIdInt
  7117. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7118. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7119. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7120. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7121. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7122. }
  7123. }
  7124. else
  7125. {
  7126. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7127. ,MESSAGE_TYPE_CALLRESULT
  7128. ,uuid
  7129. ,payload
  7130. ,connectorIdInt
  7131. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7132. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7133. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7134. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7135. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7136. {
  7137. if (idx_sample == 0)
  7138. {
  7139. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7140. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7141. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7142. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7143. }
  7144. else
  7145. {
  7146. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7147. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7148. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7149. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7150. }
  7151. }
  7152. sprintf(message + strlen(message), "]}}]");
  7153. }
  7154. LWS_Send(message);
  7155. result = TRUE;
  7156. return result;
  7157. }
  7158. int sendGetConfigurationConfirmation(char *uuid)
  7159. {
  7160. mtrace();
  7161. int result = FAIL;
  7162. int MaxKeySupported = 0;
  7163. int sentConfigurationNumber= 0;
  7164. int sentunConfigurationNumber= 0;
  7165. char message[1024*10]={0};
  7166. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7167. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7168. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7169. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7170. ,MESSAGE_TYPE_CALLRESULT
  7171. ,uuid );
  7172. //configuration key
  7173. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7174. {
  7175. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7176. {
  7177. if (sentConfigurationNumber == 0)
  7178. {
  7179. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7180. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7181. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7182. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7183. }
  7184. else
  7185. {
  7186. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7187. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7188. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7189. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7190. }
  7191. sentConfigurationNumber = sentConfigurationNumber + 1;
  7192. }
  7193. }
  7194. sprintf(message + strlen(message), "]");
  7195. if(UnknownKeynum != 0)
  7196. {
  7197. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7198. //unkown key
  7199. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7200. {
  7201. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7202. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7203. if(sentunConfigurationNumber == 0)
  7204. {
  7205. sprintf(message + strlen(message), "\"%s\""
  7206. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7207. }
  7208. else
  7209. {
  7210. sprintf(message + strlen(message), ",\"%s\""
  7211. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7212. }
  7213. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7214. }
  7215. sprintf(message + strlen(message), "]");
  7216. }
  7217. sprintf(message + strlen(message), "}]");
  7218. LWS_Send(message);
  7219. return result;
  7220. }
  7221. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7222. {
  7223. mtrace();
  7224. int result = FAIL;
  7225. char message[400]={0};
  7226. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7227. if(strcmp(payload,"")==0)
  7228. {
  7229. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7230. }
  7231. else
  7232. {
  7233. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7234. }
  7235. LWS_Send(message);
  7236. result = TRUE;
  7237. return result;
  7238. }
  7239. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7240. {
  7241. mtrace();
  7242. int result = FAIL;
  7243. char message[80]={0};
  7244. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7245. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7246. LWS_Send(message);
  7247. result = TRUE;
  7248. return result;
  7249. }
  7250. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7251. {
  7252. mtrace();
  7253. int result = FAIL;
  7254. char message[80]={0};
  7255. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7256. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7257. LWS_Send(message);
  7258. result = TRUE;
  7259. return result;
  7260. }
  7261. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7262. {
  7263. mtrace();
  7264. int result = FAIL;
  7265. char message[80]={0};
  7266. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7267. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7268. LWS_Send(message);
  7269. result = TRUE;
  7270. return result;
  7271. }
  7272. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7273. {
  7274. mtrace();
  7275. int result = FAIL;
  7276. char message[80]={0};
  7277. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7278. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7279. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7280. LWS_Send(message);
  7281. result = TRUE;
  7282. return result;
  7283. }
  7284. int sendResetConfirmation(char *uuid,char *payload)
  7285. {
  7286. mtrace();
  7287. int result = FAIL;
  7288. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7289. char message[80]={0};
  7290. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7291. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7292. LWS_Send(message);
  7293. result = TRUE;
  7294. return result;
  7295. }
  7296. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7297. {
  7298. mtrace();
  7299. int result = FAIL;
  7300. char message[500]={0};
  7301. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7302. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7303. LWS_Send(message);
  7304. result = TRUE;
  7305. return result;
  7306. }
  7307. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7308. {
  7309. mtrace();
  7310. int result = FAIL;
  7311. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7312. char message[80]={0};
  7313. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7314. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7315. LWS_Send(message);
  7316. result = TRUE;
  7317. return result;
  7318. }
  7319. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7320. {
  7321. mtrace();
  7322. int result = FAIL;
  7323. char message[80]={0};
  7324. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7325. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7326. LWS_Send(message);
  7327. result = TRUE;
  7328. return result;
  7329. }
  7330. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7331. {
  7332. mtrace();
  7333. int result = FAIL;
  7334. char message[80]={0};
  7335. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7336. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7337. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7338. LWS_Send(message);
  7339. result = TRUE;
  7340. return result;
  7341. }
  7342. int sendUpdateFirmwareConfirmation(char *uuid)
  7343. {
  7344. mtrace();
  7345. int result = FAIL;
  7346. char message[60]={0};
  7347. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7348. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7349. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7350. LWS_Send(message);
  7351. result = TRUE;
  7352. return result;
  7353. }
  7354. int sendCertificateSignedConfirmation(char *uuid)
  7355. {
  7356. mtrace();
  7357. int result = PASS;
  7358. char message[4096]={0};
  7359. json_object *CertificateSigned = json_object_new_object();
  7360. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7361. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7362. sprintf(message,"[%d,\"%s\",%s]"
  7363. ,MESSAGE_TYPE_CALLRESULT
  7364. ,uuid
  7365. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7366. json_object_put(CertificateSigned);
  7367. LWS_Send(message);
  7368. return result;
  7369. }
  7370. int sendDeleteCertificateConfirmation(char *uuid)
  7371. {
  7372. mtrace();
  7373. int result = PASS;
  7374. char message[4096]={0};
  7375. json_object *DeleteCertificate = json_object_new_object();
  7376. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7377. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7378. sprintf(message,"[%d,\"%s\",%s]"
  7379. ,MESSAGE_TYPE_CALLRESULT
  7380. ,uuid
  7381. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7382. json_object_put(DeleteCertificate);
  7383. LWS_Send(message);
  7384. return result;
  7385. }
  7386. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7387. {
  7388. mtrace();
  7389. int result = PASS;
  7390. char message[4096]={0};
  7391. json_object *ExtendedTriggerMessage = json_object_new_object();
  7392. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7393. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7394. sprintf(message,"[%d,\"%s\",%s]"
  7395. ,MESSAGE_TYPE_CALLRESULT
  7396. ,uuid
  7397. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7398. json_object_put(ExtendedTriggerMessage);
  7399. LWS_Send(message);
  7400. return result;
  7401. }
  7402. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7403. {
  7404. mtrace();
  7405. int result = PASS;
  7406. char message[4096]={0};
  7407. json_object *GetInstalledCertificateIds = json_object_new_object();
  7408. json_object *certificateHashDataDatas = json_object_new_array();
  7409. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7410. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7411. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7412. {
  7413. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7414. {
  7415. json_object *certificateHashData = json_object_new_object();
  7416. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7417. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7418. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7419. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7420. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7421. }
  7422. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7423. }
  7424. else
  7425. {
  7426. json_object_put(certificateHashDataDatas);
  7427. }
  7428. sprintf(message,"[%d,\"%s\",%s]"
  7429. ,MESSAGE_TYPE_CALLRESULT
  7430. ,uuid
  7431. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7432. json_object_put(GetInstalledCertificateIds);
  7433. LWS_Send(message);
  7434. return result;
  7435. }
  7436. int sendGetLogConfirmation(char *uuid)
  7437. {
  7438. mtrace();
  7439. int result = PASS;
  7440. char message[4096]={0};
  7441. json_object *GetLog = json_object_new_object();
  7442. DEBUG_INFO("sendGetLogConfirmation...\n");
  7443. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7444. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7445. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7446. sprintf(message,"[%d,\"%s\",%s]"
  7447. ,MESSAGE_TYPE_CALLRESULT
  7448. ,uuid
  7449. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7450. json_object_put(GetLog);
  7451. LWS_Send(message);
  7452. return result;
  7453. }
  7454. int sendInstallCertificateConfirmation(char *uuid)
  7455. {
  7456. mtrace();
  7457. int result = PASS;
  7458. char message[4096]={0};
  7459. json_object *InstallCertificate = json_object_new_object();
  7460. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7461. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7462. sprintf(message,"[%d,\"%s\",%s]"
  7463. ,MESSAGE_TYPE_CALLRESULT
  7464. ,uuid
  7465. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7466. json_object_put(InstallCertificate);
  7467. LWS_Send(message);
  7468. return result;
  7469. }
  7470. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7471. {
  7472. mtrace();
  7473. int result = PASS;
  7474. char message[4096]={0};
  7475. json_object *SignedUpdateFirmware = json_object_new_object();
  7476. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7477. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7478. sprintf(message,"[%d,\"%s\",%s]"
  7479. ,MESSAGE_TYPE_CALLRESULT
  7480. ,uuid
  7481. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7482. json_object_put(SignedUpdateFirmware);
  7483. LWS_Send(message);
  7484. return result;
  7485. }
  7486. int sendUnknownConfirmation(char *uuid)
  7487. {
  7488. mtrace();
  7489. int result = PASS;
  7490. char message[256]={0};
  7491. DEBUG_INFO("sendUnknownConfirmation...\n");
  7492. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7493. LWS_Send(message);
  7494. return result;
  7495. }
  7496. //==========================================
  7497. // Handle server request routine Start
  7498. //==========================================
  7499. int handleCancelReservationRequest(char *uuid, char *payload)
  7500. {
  7501. mtrace();
  7502. int result = FAIL;
  7503. int gunNO = 0;
  7504. int reservationIdInt = -1;
  7505. char comfirmstr[20];
  7506. DEBUG_INFO("handleCancelReservationRequest...\n");
  7507. json_object *CancelReservation;
  7508. CancelReservation = json_tokener_parse(payload);
  7509. if(!is_error(CancelReservation))
  7510. {
  7511. // Required data
  7512. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7513. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7514. }
  7515. json_object_put(CancelReservation);
  7516. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7517. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7518. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7519. if(reservationIdInt != -1)
  7520. {
  7521. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7522. //check Transaction active
  7523. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7525. {
  7526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7527. {
  7528. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7529. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7530. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7531. {
  7532. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7533. }
  7534. else
  7535. {
  7536. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7537. }
  7538. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7539. goto end;
  7540. }
  7541. }
  7542. for (int index = 0; index < CCS_QUANTITY; index++)
  7543. {
  7544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7545. {
  7546. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7547. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7548. if(gunType[2] == GUN_TYPE_CCS)
  7549. {
  7550. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7551. }
  7552. else
  7553. {
  7554. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7555. }
  7556. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7557. goto end;
  7558. }
  7559. }
  7560. for (int index = 0; index < GB_QUANTITY; index++)
  7561. {
  7562. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7563. {
  7564. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7565. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7566. if(gunType[2] == GUN_TYPE_GBT)
  7567. {
  7568. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7569. }
  7570. else
  7571. {
  7572. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7573. }
  7574. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7575. goto end;
  7576. }
  7577. }
  7578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7579. {
  7580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7581. {
  7582. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7583. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7584. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7585. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7586. goto end;
  7587. }
  7588. }
  7589. for (int index = 0; index < AC_QUANTITY; index++)
  7590. {
  7591. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7592. {
  7593. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7594. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7596. {
  7597. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7598. }
  7599. else
  7600. {
  7601. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7602. }
  7603. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7604. goto end;
  7605. }
  7606. }
  7607. }
  7608. //The reservationId does NOT match the reservationId
  7609. sendCancelReservationConfirmation(uuid, comfirmstr);
  7610. end:
  7611. // Fill in ocpp packet uuid
  7612. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7613. return result;
  7614. }
  7615. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7616. {
  7617. mtrace();
  7618. int result = FAIL;
  7619. int gunIndex = -1;
  7620. char typeStr[16]={0};
  7621. char comfirmstr[20];
  7622. int specificId = FALSE;
  7623. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7624. json_object *ChangeAvailability;
  7625. ChangeAvailability = json_tokener_parse(payload);
  7626. if(!is_error(ChangeAvailability))
  7627. {
  7628. // Required data
  7629. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7630. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7631. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7632. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7633. }
  7634. json_object_put(ChangeAvailability);
  7635. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7636. {
  7637. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7638. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7639. }
  7640. else if(gunIndex == 0)
  7641. {
  7642. for(int i=0; i < gunTotalNumber; i++)
  7643. {
  7644. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7645. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7646. }
  7647. }
  7648. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7650. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7651. {
  7652. specificId = TRUE;
  7653. }
  7654. if(specificId == FALSE)
  7655. goto end;
  7656. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7657. {
  7658. //----------------------gunIndex is 0 ------------------------------------------------//
  7659. if(gunIndex == 0)
  7660. {
  7661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7662. {
  7663. for(int i=0; i < gunTotalNumber; i++)
  7664. {
  7665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7666. {
  7667. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7668. {
  7669. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7670. {
  7671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7672. goto end;
  7673. }
  7674. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7678. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7679. {
  7680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7681. goto end;
  7682. }
  7683. }
  7684. }//END FOR CHAdeMO_QUANTITY
  7685. for (int index = 0; index < CCS_QUANTITY; index++)
  7686. {
  7687. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7688. {
  7689. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7690. {
  7691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7692. goto end;
  7693. }
  7694. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7695. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7696. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7697. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7698. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7699. {
  7700. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7701. goto end;
  7702. }
  7703. }
  7704. }//END FOR CCS_QUANTITY
  7705. for (int index = 0; index < GB_QUANTITY; index++)
  7706. {
  7707. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7708. {
  7709. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7710. {
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7712. goto end;
  7713. }
  7714. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7715. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7716. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7717. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7718. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7719. {
  7720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7721. goto end;
  7722. }
  7723. }
  7724. }// END FOR GB_QUANTITY
  7725. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7726. {
  7727. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7728. {
  7729. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7730. {
  7731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7732. goto end;
  7733. }
  7734. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7735. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7736. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7737. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7738. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7739. {
  7740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7741. goto end;
  7742. }
  7743. }
  7744. }// END FOR GENERAL_GUN_QUANTITY
  7745. for (int index = 0; index < AC_QUANTITY; index++)
  7746. {
  7747. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7748. {
  7749. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7750. {
  7751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7752. goto end;
  7753. }
  7754. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7755. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7756. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7757. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7758. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7759. {
  7760. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7761. goto end;
  7762. }
  7763. }
  7764. }//END FOR AC_QUANTITY
  7765. }// END FOR gunTotalNumber
  7766. }
  7767. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7768. {
  7769. for(int i=0; i < gunTotalNumber; i++)
  7770. {
  7771. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7772. {
  7773. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7774. goto end;
  7775. }
  7776. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7777. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7780. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7781. {
  7782. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7783. goto end;
  7784. }
  7785. }
  7786. }
  7787. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7788. goto end;
  7789. }
  7790. //----------------------gunIndex is not 0 ------------------------------------------------//
  7791. //check Transaction active
  7792. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7793. {
  7794. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7795. {
  7796. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7797. {
  7798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7799. goto end;
  7800. }
  7801. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7802. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7803. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7804. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7805. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7806. {
  7807. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7808. goto end;
  7809. }
  7810. else
  7811. {
  7812. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7813. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7814. goto end;
  7815. }
  7816. }
  7817. }//END FOR CHAdeMO_QUANTITY
  7818. for (int index = 0; index < CCS_QUANTITY; index++)
  7819. {
  7820. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7821. {
  7822. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7823. {
  7824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7825. goto end;
  7826. }
  7827. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7828. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7829. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7830. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7831. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7832. {
  7833. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7834. goto end;
  7835. }
  7836. else
  7837. {
  7838. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7839. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7840. goto end;
  7841. }
  7842. }
  7843. }//END FOR CCS_QUANTITY
  7844. for (int index = 0; index < GB_QUANTITY; index++)
  7845. {
  7846. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7847. {
  7848. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7849. {
  7850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7851. goto end;
  7852. }
  7853. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7854. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7855. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7856. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7857. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7858. {
  7859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7860. goto end;
  7861. }
  7862. else
  7863. {
  7864. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7866. goto end;
  7867. }
  7868. }
  7869. }// END FOR GB_QUANTITY
  7870. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7871. {
  7872. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7873. {
  7874. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7875. {
  7876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7877. goto end;
  7878. }
  7879. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7880. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7881. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7882. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7883. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7884. {
  7885. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7886. goto end;
  7887. }
  7888. else
  7889. {
  7890. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7891. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7892. goto end;
  7893. }
  7894. }
  7895. }// END FOR GENERAL_GUN_QUANTITY
  7896. for (int index = 0; index < AC_QUANTITY; index++)
  7897. {
  7898. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7899. {
  7900. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7901. {
  7902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7903. goto end;
  7904. }
  7905. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7906. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7907. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7908. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7909. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7910. {
  7911. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7912. goto end;
  7913. }
  7914. else
  7915. {
  7916. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7917. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7918. goto end;
  7919. }
  7920. }
  7921. }//END FOR AC_QUANTITY
  7922. }//END FOR AvailabilityTypeStr[Inoperative]
  7923. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7924. {
  7925. //----------------------gunIndex is 0 ------------------------------------------------//
  7926. if(gunIndex == 0)
  7927. {
  7928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7929. {
  7930. for(int i=0; i < gunTotalNumber; i++)
  7931. {
  7932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7933. {
  7934. 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
  7935. {
  7936. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7937. goto end;
  7938. }
  7939. }//END FOR CHAdeMO_QUANTITY
  7940. for (int index = 0; index < CCS_QUANTITY; index++)
  7941. {
  7942. 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
  7943. {
  7944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7945. goto end;
  7946. }
  7947. }//END FOR CCS_QUANTITY
  7948. for (int index = 0; index < GB_QUANTITY; index++)
  7949. {
  7950. 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
  7951. {
  7952. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7954. goto end;
  7955. }
  7956. }// END FOR GB_QUANTITY
  7957. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7958. {
  7959. 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
  7960. {
  7961. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7963. goto end;
  7964. }
  7965. }// END FOR GENERAL_GUN_QUANTITY
  7966. for (int index = 0; index < AC_QUANTITY; index++)
  7967. {
  7968. 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
  7969. {
  7970. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7971. goto end;
  7972. }
  7973. }//END FOR CHAdeMO_QUANTITY
  7974. }// END FOR gunTotalNumber
  7975. }
  7976. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7977. {
  7978. for(int i=0; i < gunTotalNumber; i++)
  7979. {
  7980. for (int index = 0; index < AC_QUANTITY; index++)
  7981. {
  7982. 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
  7983. {
  7984. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7985. goto end;
  7986. }
  7987. }//END FOR CHAdeMO_QUANTITY
  7988. } // END FOR gunTotalNumber
  7989. }
  7990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7991. goto end;
  7992. }
  7993. //----------------------gunIndex is not 0 ------------------------------------------------//
  7994. //check Transaction active
  7995. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7996. {
  7997. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7998. {
  7999. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8000. goto end;
  8001. }
  8002. }//END FOR CHAdeMO_QUANTITY
  8003. for (int index = 0; index < CCS_QUANTITY; index++)
  8004. {
  8005. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8006. {
  8007. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8008. goto end;
  8009. }
  8010. }//END FOR CCS_QUANTITY
  8011. for (int index = 0; index < GB_QUANTITY; index++)
  8012. {
  8013. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8014. {
  8015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8016. goto end;
  8017. }
  8018. }// END FOR GB_QUANTITY
  8019. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8020. {
  8021. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8022. {
  8023. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8024. goto end;
  8025. }
  8026. }// END FOR GENERAL_GUN_QUANTITY
  8027. for (int index = 0; index < AC_QUANTITY; index++)
  8028. {
  8029. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8030. {
  8031. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8032. goto end;
  8033. }
  8034. }//END FOR AC_QUANTITY
  8035. }//END FOR AvailabilityTypeStr[Operative]
  8036. end:
  8037. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8038. {
  8039. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8040. }
  8041. else
  8042. {
  8043. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8044. }
  8045. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8046. {
  8047. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8048. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8049. }
  8050. else if(gunIndex == 0)
  8051. {
  8052. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8053. {
  8054. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8055. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8056. }
  8057. }
  8058. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8059. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8060. return result;
  8061. }
  8062. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8063. {
  8064. mtrace();
  8065. int valueInvalid = NO;
  8066. int result = FAIL;
  8067. char keystr[40]={0};
  8068. char valuestr[501]={0}; //value should be limited in 500 bytes
  8069. char comfirmstr[20]={0};
  8070. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8071. json_object *ChangeConfiguration;
  8072. ChangeConfiguration = json_tokener_parse(payload);
  8073. if(!is_error(ChangeConfiguration))
  8074. {
  8075. // Required data
  8076. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8077. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8078. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8079. {
  8080. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8081. }
  8082. else
  8083. {
  8084. valueInvalid = YES;
  8085. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8086. }
  8087. }
  8088. json_object_put(ChangeConfiguration);
  8089. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8090. {
  8091. DEBUG_ERROR("Payload is null or not accepted.\n");
  8092. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8093. }
  8094. else
  8095. {
  8096. int status = setKeyValue(keystr, valuestr);
  8097. switch(status)
  8098. {
  8099. case ConfigurationStatus_Accepted:
  8100. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8101. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8102. StoreConfigurationTable();
  8103. break;
  8104. case RebootRequired:
  8105. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8106. StoreConfigurationTable();
  8107. break;
  8108. case NotSupported:
  8109. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8110. break;
  8111. case ConfigurationStatus_Rejected:
  8112. default:
  8113. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8114. break;
  8115. }
  8116. }
  8117. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8118. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8119. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8120. {
  8121. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8122. SetOcppConnStatus(FALSE);
  8123. }
  8124. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8125. {
  8126. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8127. }
  8128. return result;
  8129. }
  8130. int handleClearCacheRequest(char *uuid, char *payload)
  8131. {
  8132. mtrace();
  8133. int result = FAIL;
  8134. char comfirmstr[20];
  8135. char rmFileCmd[100]={0};
  8136. struct stat stats;
  8137. DEBUG_INFO("handleClearCacheRequest...\n");
  8138. stat("/Storage/OCPP_PH", &stats);
  8139. // Check for directory existence
  8140. if (S_ISDIR(stats.st_mode) == 1)
  8141. {}
  8142. else
  8143. {
  8144. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8145. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8146. system(rmFileCmd);
  8147. }
  8148. if(OCPP_cleanLocalCache())
  8149. {
  8150. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8151. }
  8152. else
  8153. {
  8154. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8155. }
  8156. sendClearCacheConfirmation(uuid, comfirmstr);
  8157. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8158. return result;
  8159. }
  8160. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8161. {
  8162. mtrace();
  8163. int result = FAIL;
  8164. int resultRename;
  8165. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8166. char chargingProfilePurposeStr[26]={0};
  8167. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8168. char tempchargingProfilePurposeStr[26]={0};
  8169. char str[100]={0};
  8170. char fname[200]={0};
  8171. char comfirmstr[20]={0};
  8172. char word[1600]={0};
  8173. int clearflag = FALSE;
  8174. int chargingProfileIdIsNULL = FALSE;
  8175. int connectorIsNULL = FALSE;
  8176. int chargingProfilePurposeIsNULL = FALSE;
  8177. int stackLevelIsNULL = FALSE;
  8178. //int GotoEnd = FALSE;
  8179. FILE *fptr1, *fptr2;
  8180. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8181. int n_chargingProfile=0;
  8182. int isEmptyFile = FALSE;
  8183. char sLineWord[1600]={0};
  8184. char chargingProfiles[10][100]={0};
  8185. int ChargeProfileCount = 0;
  8186. int ch;
  8187. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8188. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8189. json_object *ClearChargingProfile;
  8190. ClearChargingProfile = json_tokener_parse(payload);
  8191. if(!is_error(ClearChargingProfile))
  8192. {
  8193. // Optional data
  8194. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8195. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8196. else
  8197. chargingProfileIdIsNULL = TRUE;
  8198. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8199. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8200. else
  8201. connectorIsNULL = TRUE;
  8202. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8203. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8204. else
  8205. chargingProfilePurposeIsNULL = TRUE;
  8206. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8207. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8208. else
  8209. stackLevelIsNULL = TRUE;
  8210. }
  8211. json_object_put(ClearChargingProfile);
  8212. if(connectorIsNULL == FALSE)
  8213. {
  8214. switch(connectorIdInt)
  8215. {
  8216. case 0:
  8217. if(chargingProfilePurposeIsNULL == TRUE)
  8218. {
  8219. int l = 0;
  8220. strcpy(fname, ChargePointMaxProfile_JSON);
  8221. if((access(fname,F_OK))!=-1)
  8222. {
  8223. strcpy(chargingProfiles[l], fname);
  8224. l = l + 1;
  8225. }
  8226. strcpy(fname, TxDefaultProfile_0_JSON);
  8227. if((access(fname,F_OK))!=-1)
  8228. {
  8229. strcpy(chargingProfiles[l], fname);
  8230. l = l + 1;
  8231. }
  8232. ChargeProfileCount = l;
  8233. }
  8234. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8235. {
  8236. strcpy(fname, ChargePointMaxProfile_JSON);
  8237. if((access(fname,F_OK))!=-1)
  8238. {
  8239. strcpy(chargingProfiles[0], fname);
  8240. ChargeProfileCount = 1;
  8241. }
  8242. }
  8243. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8244. {
  8245. strcpy(fname, TxDefaultProfile_0_JSON);
  8246. if((access(fname,F_OK))!=-1)
  8247. {
  8248. strcpy(chargingProfiles[0], fname);
  8249. ChargeProfileCount = 1;
  8250. }
  8251. }
  8252. break;
  8253. default:
  8254. if(chargingProfilePurposeIsNULL == TRUE)
  8255. {
  8256. int m = 0;
  8257. memset(fname, 0, ARRAY_SIZE(fname));
  8258. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8259. if((access(fname,F_OK))!=-1)
  8260. {
  8261. strcpy(chargingProfiles[m], fname);
  8262. m = m + 1;
  8263. }
  8264. memset(fname, 0, ARRAY_SIZE(fname));
  8265. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8266. if((access(fname,F_OK))!=-1)
  8267. {
  8268. strcpy(chargingProfiles[m], fname);
  8269. m = m + 1;
  8270. }
  8271. ChargeProfileCount = m;
  8272. }
  8273. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8274. {
  8275. //strcpy(fname, TxDefaultProfile_1_JSON);
  8276. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8277. if((access(fname,F_OK))!=-1)
  8278. {
  8279. strcpy(chargingProfiles[0], fname);
  8280. ChargeProfileCount = 1;
  8281. }
  8282. }
  8283. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8284. {
  8285. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8286. if((access(fname,F_OK))!=-1)
  8287. {
  8288. strcpy(chargingProfiles[0], fname);
  8289. ChargeProfileCount = 1;
  8290. }
  8291. //strcpy(fname, TxProfile_1_JSON);
  8292. }
  8293. //strcpy(fname, ChargePointMaxProfile_JSON );
  8294. break;
  8295. }
  8296. }
  8297. else // Check all Charging Profiles
  8298. {
  8299. int i = 0;
  8300. char fnametemp[200]={0};
  8301. ChargeProfileCount = 0;
  8302. //Check ChargePointMaxProfile.json exit
  8303. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8304. {
  8305. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8306. i = i + 1;
  8307. }
  8308. //Check TxDefaultProfile_0.json exit
  8309. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8310. {
  8311. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8312. i = i + 1;
  8313. }
  8314. //Check TxDefaultProfile_%d.json
  8315. for(int j=1; j <= gunTotalNumber; j++)
  8316. {
  8317. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8318. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8319. if((access(fnametemp,F_OK))!=-1)
  8320. {
  8321. strcpy(chargingProfiles[i], fnametemp);
  8322. i = i + 1;
  8323. }
  8324. }
  8325. //Check TxProfile_%d.json
  8326. for(int j=1; j <= gunTotalNumber; j++)
  8327. {
  8328. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8329. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8330. if((access(fnametemp,F_OK))!=-1)
  8331. {
  8332. strcpy(chargingProfiles[i], fnametemp);
  8333. i = i + 1;
  8334. }
  8335. }
  8336. ChargeProfileCount = i;
  8337. }// End connectorIsNULL is TRUE
  8338. if(ChargeProfileCount == 0)
  8339. {
  8340. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8341. goto end;
  8342. }
  8343. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8344. {
  8345. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8346. goto end;
  8347. }
  8348. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8349. {
  8350. memset(str, 0, ARRAY_SIZE(str));
  8351. // clear temp file
  8352. sprintf(str,"rm -f %s",temp);
  8353. system(str);
  8354. for(int k=0; k < ChargeProfileCount; k++)
  8355. {
  8356. memset(str, 0, ARRAY_SIZE(str));
  8357. //clear file in C
  8358. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8359. system(str);
  8360. }
  8361. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8362. goto end;
  8363. }
  8364. else if(connectorIsNULL == TRUE)
  8365. {
  8366. for(int k=0; k < ChargeProfileCount; k++)
  8367. {
  8368. fptr1 = fopen(chargingProfiles[k], "r");
  8369. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8370. //Check Charging Profile Count
  8371. while(fscanf(fptr1, "%s", word) != EOF)
  8372. {
  8373. //DEBUG_INFO("word=%s\n",word);
  8374. if(strstr(word, "chargingProfileId")!= NULL)
  8375. {
  8376. //DEBUG_INFO("test chargingProfileId \n");
  8377. n_chargingProfile = n_chargingProfile + 1;
  8378. //DEBUG_INFO("chargingProfileId Found\n");
  8379. }
  8380. }
  8381. rewind(fptr1);
  8382. //search Charging Profile Element
  8383. //int i= 0;
  8384. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8385. {
  8386. json_object *tmpProfilee;
  8387. tmpProfilee = json_tokener_parse(sLineWord);
  8388. if(!is_error(tmpProfilee))
  8389. {
  8390. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8391. {
  8392. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8393. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8394. }
  8395. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8396. {
  8397. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8398. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8399. }
  8400. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8401. {
  8402. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8403. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8404. }
  8405. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8406. {
  8407. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8408. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8409. }
  8410. }
  8411. json_object_put(tmpProfilee);
  8412. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8413. {
  8414. //------- not write to fptr2-------//
  8415. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8416. //clearflag = TRUE;
  8417. }
  8418. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8419. {
  8420. //------- not write to fptr2-------//
  8421. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8422. }
  8423. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8424. {
  8425. //------- not write to fptr2-------//
  8426. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8427. }
  8428. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8429. {
  8430. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8431. }
  8432. else
  8433. {
  8434. fprintf(fptr2, sLineWord);//writing data into file
  8435. }
  8436. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8437. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8438. if(clearflag == TRUE)
  8439. {
  8440. fclose(fptr1);
  8441. fclose(fptr2);
  8442. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8443. system(str);
  8444. // clear temp file
  8445. sprintf(str,"rm -f %s",temp);
  8446. system(str);
  8447. }
  8448. else
  8449. {
  8450. fclose(fptr1);
  8451. fclose(fptr2);
  8452. memset(str, 0, ARRAY_SIZE(str));
  8453. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8454. system(str);
  8455. resultRename = rename(temp, chargingProfiles[k]);
  8456. if(resultRename == 0)
  8457. {
  8458. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8459. }
  8460. else
  8461. {
  8462. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8463. }
  8464. if(comfirmstr[0]== 0)
  8465. {
  8466. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8467. }
  8468. //Check chargingProfile is empty file
  8469. /*------ Read the file ----------------*/
  8470. fptr1=fopen(chargingProfiles[k],"r");
  8471. ch=fgetc(fptr1);
  8472. rewind(fptr1);
  8473. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8474. if(ch!=EOF)
  8475. {
  8476. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8477. {
  8478. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8479. if(sLineWord[0]=='\0')
  8480. {
  8481. isEmptyFile = TRUE;
  8482. break;
  8483. }
  8484. else
  8485. {
  8486. isEmptyFile = FALSE;
  8487. break;
  8488. }
  8489. }
  8490. }
  8491. else
  8492. isEmptyFile = TRUE;
  8493. fclose(fptr1);
  8494. if(isEmptyFile == TRUE)
  8495. {
  8496. memset(str, 0, ARRAY_SIZE(str));
  8497. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8498. system(str);
  8499. }
  8500. }
  8501. }// End of while(int k=0; k < ChargePointCount; k++)
  8502. }
  8503. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8504. {
  8505. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8506. for(int k=0; k < ChargeProfileCount; k++)
  8507. {
  8508. fptr1 = fopen(chargingProfiles[k], "r");
  8509. fptr2 = fopen(temp, "w+");
  8510. //Check Charging Profile Count
  8511. while(fscanf(fptr1, "%s", word) != EOF)
  8512. {
  8513. //DEBUG_INFO("word=%s\n",word);
  8514. if(strstr(word, "chargingProfileId")!= NULL)
  8515. {
  8516. n_chargingProfile = n_chargingProfile + 1;
  8517. }
  8518. }
  8519. rewind(fptr1);
  8520. //search Charging Profile Element
  8521. //int i= 0;
  8522. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8523. {
  8524. json_object *tmpProfilee;
  8525. tmpProfilee = json_tokener_parse(sLineWord);
  8526. if(!is_error(tmpProfilee))
  8527. {
  8528. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8529. {
  8530. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8531. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8532. }
  8533. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8534. {
  8535. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8536. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8537. }
  8538. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8539. {
  8540. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8541. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8542. }
  8543. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8544. {
  8545. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8546. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8547. }
  8548. }
  8549. json_object_put(tmpProfilee);
  8550. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8551. {
  8552. //------- not write to fptr2-------//
  8553. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8554. //clearflag = TRUE;
  8555. }
  8556. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8557. {
  8558. //------- not write to fptr2-------//
  8559. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8560. }
  8561. else if(stackLevelIsNULL == TRUE)
  8562. {
  8563. //Clear Whole File
  8564. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8565. clearflag = TRUE;
  8566. break;
  8567. }
  8568. else
  8569. {
  8570. fprintf(fptr2, sLineWord);//writing data into file
  8571. }
  8572. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8573. }
  8574. if(clearflag == TRUE)
  8575. {
  8576. fclose(fptr1);
  8577. fclose(fptr2);
  8578. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8579. system(str);
  8580. // clear temp file
  8581. sprintf(str,"rm -f %s",temp);
  8582. system(str);
  8583. }
  8584. else
  8585. {
  8586. fclose(fptr1);
  8587. fclose(fptr2);
  8588. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8589. system(str);
  8590. resultRename = rename(temp, chargingProfiles[k]);
  8591. if(resultRename == 0)
  8592. {
  8593. DEBUG_INFO("File ChargingProfile renamed successfully");
  8594. }
  8595. else
  8596. {
  8597. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8598. }
  8599. if(comfirmstr[0]== 0)
  8600. {
  8601. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8602. }
  8603. //Check chargingProfile is empty file
  8604. /*------ Read the file ----------------*/
  8605. fptr1=fopen(chargingProfiles[k],"r");
  8606. ch=fgetc(fptr1);
  8607. rewind(fptr1);
  8608. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8609. if(ch!=EOF)
  8610. {
  8611. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8612. {
  8613. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8614. if(sLineWord[0]=='\0')
  8615. {
  8616. isEmptyFile = TRUE;
  8617. break;
  8618. }
  8619. else
  8620. {
  8621. isEmptyFile = FALSE;
  8622. break;
  8623. }
  8624. }
  8625. }
  8626. else
  8627. isEmptyFile = TRUE;
  8628. fclose(fptr1);
  8629. if(isEmptyFile == TRUE)
  8630. {
  8631. memset(str, 0, ARRAY_SIZE(str));
  8632. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8633. system(str);
  8634. }
  8635. /*------- End of reading ---------------*/
  8636. }
  8637. } // while(int k=0; k < ChargeProfileCount; k++)
  8638. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8639. end:
  8640. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8641. {
  8642. if(connectorIdInt == 0)
  8643. {
  8644. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8645. {
  8646. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8647. }
  8648. }
  8649. else
  8650. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8651. }
  8652. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8653. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8654. return result;
  8655. }
  8656. void createFirmwareVersionByDataTransfer(void)
  8657. {
  8658. json_object *FirmwareDataTransfer = json_object_new_object();
  8659. // AC & DC model
  8660. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8661. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8662. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8663. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8664. // DC model
  8665. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8666. {
  8667. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8668. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8669. (gunType[3] != GUN_TYPE_UNKNOWN))
  8670. {
  8671. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8672. }
  8673. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8674. {
  8675. // DS DM DW
  8676. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8677. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8678. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8679. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8680. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8681. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8682. }
  8683. else
  8684. {
  8685. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8686. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8687. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8688. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8689. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8690. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8691. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8692. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8693. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8694. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8695. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8696. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8697. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8698. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8699. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8700. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8701. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8702. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8703. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8704. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8705. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8706. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8707. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8708. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8709. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8710. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8711. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8712. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8713. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8714. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8715. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8716. }
  8717. }
  8718. // 4G model
  8719. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8720. {
  8721. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8722. }
  8723. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8724. json_object_put(FirmwareDataTransfer);
  8725. }
  8726. int handleDataTransferRequest(char *uuid, char *payload)
  8727. {
  8728. mtrace();
  8729. json_object *response = json_object_new_object();
  8730. int result = FAIL;
  8731. char tempvendorId[255]={0};
  8732. char tempmessageId[50]={0};
  8733. char tempdata[512]={0};
  8734. char message[2048]={0};
  8735. DEBUG_INFO("handleDataTransferRequest...\n");
  8736. if((uuid != NULL) && (payload != NULL))
  8737. {
  8738. json_object *DataTransfer;
  8739. DataTransfer = json_tokener_parse(payload);
  8740. if(!is_error(DataTransfer))
  8741. {
  8742. // Required data
  8743. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8744. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8745. // Optional data
  8746. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8747. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8748. if(json_object_object_get(DataTransfer, "data") != NULL)
  8749. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8750. result = PASS;
  8751. }
  8752. json_object_put(DataTransfer);
  8753. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8754. {
  8755. // Send all moudle firmware version on EVSE
  8756. createFirmwareVersionByDataTransfer();
  8757. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8758. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8759. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8760. json_object_put(response);
  8761. }
  8762. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8763. {
  8764. system("/usr/bin/run_tmate_restart.sh &");
  8765. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8766. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8767. json_object_put(response);
  8768. }
  8769. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8770. {
  8771. json_object *data;
  8772. data = json_tokener_parse(tempdata);
  8773. if(!is_error(data))
  8774. {
  8775. 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))
  8776. {
  8777. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8778. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8779. if(json_object_object_get(data, "SOC") != NULL)
  8780. {
  8781. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8782. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8783. }
  8784. if(json_object_object_get(data, "Energy") != NULL)
  8785. {
  8786. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8787. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8788. }
  8789. if(json_object_object_get(data, "Duration") != NULL)
  8790. {
  8791. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8792. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8793. }
  8794. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8795. }
  8796. else
  8797. {
  8798. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8799. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8800. }
  8801. }
  8802. else
  8803. {
  8804. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8805. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8806. }
  8807. json_object_put(data);
  8808. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8809. json_object_put(response);
  8810. }
  8811. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8812. {
  8813. json_object *data;
  8814. data = json_tokener_parse(tempdata);
  8815. if(!is_error(data))
  8816. {
  8817. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8818. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8819. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8820. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8821. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8822. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8823. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8824. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8825. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8826. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8827. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8828. }
  8829. else
  8830. {
  8831. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8832. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8833. }
  8834. json_object_put(data);
  8835. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8836. json_object_put(response);
  8837. }
  8838. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8839. {
  8840. json_object *data;
  8841. data = json_tokener_parse(tempdata);
  8842. if(!is_error(data))
  8843. {
  8844. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8845. if(json_object_object_get(data, "idToken") != NULL)
  8846. {
  8847. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8848. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8849. }
  8850. if(json_object_object_get(data, "price") != NULL)
  8851. {
  8852. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8853. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8854. }
  8855. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8856. }
  8857. else
  8858. {
  8859. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8860. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8861. }
  8862. json_object_put(data);
  8863. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8864. json_object_put(response);
  8865. }
  8866. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8867. {
  8868. json_object *data;
  8869. data = json_tokener_parse(tempdata);
  8870. if(!is_error(data))
  8871. {
  8872. if(json_object_object_get(data, "txId") != NULL)
  8873. {
  8874. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8875. for(int idx = 0;idx<gunTotalNumber;idx++)
  8876. {
  8877. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8878. {
  8879. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8880. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8881. if(json_object_object_get(data, "description") != NULL)
  8882. {
  8883. // California pricing V1.0
  8884. DEBUG_INFO("California pricing V1.0\n");
  8885. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8886. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8887. }
  8888. else
  8889. {
  8890. // California pricing V1.1
  8891. DEBUG_INFO("California pricing V1.1\n");
  8892. if(json_object_object_get(data, "timestamp") != NULL)
  8893. {
  8894. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8895. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8896. }
  8897. if(json_object_object_get(data, "meterValue") != NULL)
  8898. {
  8899. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8900. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8901. }
  8902. if(json_object_object_get(data, "cost") != NULL)
  8903. {
  8904. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8905. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8906. }
  8907. if(json_object_object_get(data, "state") != NULL)
  8908. {
  8909. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8910. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8911. }
  8912. if(json_object_object_get(data, "chargingPrice") != NULL)
  8913. {
  8914. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8915. {
  8916. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8917. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8918. }
  8919. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8920. {
  8921. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8922. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8923. }
  8924. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8925. {
  8926. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8927. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8928. }
  8929. }
  8930. if(json_object_object_get(data, "idlePrice") != NULL)
  8931. {
  8932. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8933. {
  8934. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8935. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8936. }
  8937. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8938. {
  8939. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8940. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8941. }
  8942. }
  8943. if(json_object_object_get(data, "nextPeriod") != NULL)
  8944. {
  8945. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8946. {
  8947. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8948. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8949. }
  8950. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8951. {
  8952. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8953. {
  8954. 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")));
  8955. 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"));
  8956. }
  8957. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8958. {
  8959. 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")));
  8960. 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"));
  8961. }
  8962. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8963. {
  8964. 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")));
  8965. 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"));
  8966. }
  8967. }
  8968. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8969. {
  8970. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8971. {
  8972. 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")));
  8973. 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"));
  8974. }
  8975. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8976. {
  8977. 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")));
  8978. 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"));
  8979. }
  8980. }
  8981. }
  8982. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8983. {
  8984. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8985. {
  8986. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8987. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8988. }
  8989. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8990. {
  8991. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8992. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8993. }
  8994. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8995. {
  8996. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8997. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8998. }
  8999. }
  9000. }
  9001. }
  9002. }
  9003. }
  9004. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9005. }
  9006. else
  9007. {
  9008. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9009. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9010. }
  9011. json_object_put(data);
  9012. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9013. json_object_put(response);
  9014. }
  9015. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9016. {
  9017. json_object *data;
  9018. data = json_tokener_parse(tempdata);
  9019. if(!is_error(data))
  9020. {
  9021. if(json_object_object_get(data, "txId") != NULL)
  9022. {
  9023. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9024. for(int idx = 0;idx<gunTotalNumber;idx++)
  9025. {
  9026. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9027. {
  9028. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9029. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9030. if(json_object_object_get(data, "description") != NULL)
  9031. {
  9032. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9033. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9034. }
  9035. }
  9036. }
  9037. }
  9038. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9039. }
  9040. else
  9041. {
  9042. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9043. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9044. }
  9045. json_object_put(data);
  9046. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9047. json_object_put(response);
  9048. }
  9049. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9050. {
  9051. json_object *data;
  9052. data = json_tokener_parse(tempdata);
  9053. if(!is_error(data))
  9054. {
  9055. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9056. if(json_object_object_get(data, "Content_Type") != NULL)
  9057. {
  9058. 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))
  9059. {
  9060. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9061. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9062. {
  9063. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9064. }
  9065. }
  9066. else
  9067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9068. }
  9069. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9070. }
  9071. else
  9072. {
  9073. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9074. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9075. }
  9076. json_object_put(data);
  9077. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9078. json_object_put(response);
  9079. }
  9080. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9081. {
  9082. json_object *data;
  9083. data = json_tokener_parse(tempdata);
  9084. if(!is_error(data))
  9085. {
  9086. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9087. if(json_object_object_get(data, "ConnectorId") != NULL)
  9088. {
  9089. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9090. }
  9091. if(json_object_object_get(data, "SerialNo") != NULL)
  9092. {
  9093. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9094. }
  9095. if(json_object_object_get(data, "Page_Index") != NULL)
  9096. {
  9097. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9098. }
  9099. if(json_object_object_get(data, "Duration") != NULL)
  9100. {
  9101. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9102. }
  9103. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9104. }
  9105. else
  9106. {
  9107. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9108. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9109. }
  9110. json_object_put(data);
  9111. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9112. json_object_put(response);
  9113. }
  9114. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9115. {
  9116. json_object *data;
  9117. data = json_tokener_parse(tempdata);
  9118. if(!is_error(data))
  9119. {
  9120. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9121. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9122. {
  9123. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9124. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9125. else
  9126. {
  9127. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9128. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9129. }
  9130. }
  9131. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9132. {
  9133. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9134. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9135. else
  9136. {
  9137. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9138. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9139. }
  9140. }
  9141. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9142. {
  9143. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9144. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9145. else
  9146. {
  9147. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9148. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9149. }
  9150. }
  9151. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9152. {
  9153. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9154. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9155. else
  9156. {
  9157. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9158. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9159. }
  9160. }
  9161. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9162. {
  9163. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9164. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9165. else
  9166. {
  9167. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9168. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9169. }
  9170. }
  9171. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9172. {
  9173. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9174. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9175. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9176. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9177. else
  9178. {
  9179. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9180. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9181. }
  9182. }
  9183. if(json_object_object_get(data, "isAuthentication") != NULL)
  9184. {
  9185. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9186. {
  9187. case 0:
  9188. case 1:
  9189. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9190. break;
  9191. default:
  9192. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9193. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9194. break;
  9195. }
  9196. }
  9197. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9198. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9199. }
  9200. else
  9201. {
  9202. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9203. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9204. }
  9205. json_object_put(data);
  9206. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9207. json_object_put(response);
  9208. }
  9209. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9210. {
  9211. json_object *data;
  9212. data = json_tokener_parse(tempdata);
  9213. if(!is_error(data))
  9214. {
  9215. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9216. if(json_object_object_get(data, "stationName") != NULL)
  9217. {
  9218. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9219. }
  9220. else
  9221. {
  9222. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9223. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9224. }
  9225. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9226. {
  9227. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9228. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9229. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9230. }
  9231. }
  9232. else
  9233. {
  9234. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9235. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9236. }
  9237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9238. json_object_put(response);
  9239. }
  9240. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9241. {
  9242. json_object *data;
  9243. data = json_tokener_parse(tempdata);
  9244. if(!is_error(data))
  9245. {
  9246. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9247. if(json_object_object_get(data, "weatherId") != NULL)
  9248. {
  9249. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9250. }
  9251. else
  9252. {
  9253. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9254. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9255. }
  9256. if(json_object_object_get(data, "Temperature") != NULL)
  9257. {
  9258. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9259. }
  9260. else
  9261. {
  9262. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9263. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9264. }
  9265. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9266. {
  9267. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9268. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9269. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9270. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9271. }
  9272. }
  9273. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9274. {
  9275. json_object *data;
  9276. data = json_tokener_parse(tempdata);
  9277. if(!is_error(data))
  9278. {
  9279. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9280. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9281. {
  9282. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9283. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9284. }
  9285. else
  9286. {
  9287. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9288. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9289. }
  9290. }
  9291. else
  9292. {
  9293. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9294. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9295. }
  9296. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9297. json_object_put(response);
  9298. }
  9299. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9300. {
  9301. json_object *data;
  9302. data = json_tokener_parse(tempdata);
  9303. if(!is_error(data))
  9304. {
  9305. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9306. {
  9307. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9308. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9309. if(gun_index < gunTotalNumber)
  9310. {
  9311. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9312. {
  9313. json_object *responsedata = json_object_new_object();
  9314. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9315. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9316. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9317. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9318. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9319. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9320. }
  9321. else
  9322. {
  9323. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9324. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9325. }
  9326. }
  9327. else
  9328. {
  9329. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9330. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9331. }
  9332. }
  9333. else
  9334. {
  9335. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9336. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9337. }
  9338. }
  9339. else
  9340. {
  9341. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9342. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9343. }
  9344. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9345. json_object_put(response);
  9346. }
  9347. else
  9348. {
  9349. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9350. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9351. }
  9352. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9353. json_object_put(response);
  9354. }
  9355. else
  9356. {
  9357. // Can not find valid message id
  9358. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9359. }
  9360. }
  9361. else
  9362. {
  9363. // Payload is null
  9364. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9365. }
  9366. LWS_Send(message);
  9367. return result;
  9368. }
  9369. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9370. {
  9371. mtrace();
  9372. int result = FAIL;
  9373. int connectorIdInt, durationInt;
  9374. char chargingRateUnitStr[4]={0};
  9375. char comfirmstr[20];
  9376. int confirmPeriods = 0;
  9377. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9378. json_object *GetCompositeSchedule;
  9379. GetCompositeSchedule = json_tokener_parse(payload);
  9380. if(!is_error(GetCompositeSchedule))
  9381. {
  9382. // Required data
  9383. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9384. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9385. else
  9386. connectorIdInt = -1;
  9387. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9388. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9389. else
  9390. durationInt = 86400;
  9391. // Optional data
  9392. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9393. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9394. }
  9395. json_object_put(GetCompositeSchedule);
  9396. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9397. if((connectorIdInt == 0) ||
  9398. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9399. {
  9400. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9401. struct StructChargingProfile tmpProfile[1];
  9402. if(strstr(chargingRateUnitStr, "W") != NULL)
  9403. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9404. else
  9405. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9406. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9407. {
  9408. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9409. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9410. }
  9411. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9412. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9413. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9414. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9415. {
  9416. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9417. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9418. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9419. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9420. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9421. {
  9422. confirmPeriods = idx;
  9423. break;
  9424. }
  9425. }
  9426. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9427. {
  9428. confirmPeriods += 1;
  9429. }
  9430. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9431. }
  9432. else
  9433. {
  9434. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9435. }
  9436. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9437. return result;
  9438. }
  9439. int handleGetConfigurationRequest(char *uuid, char *payload)
  9440. {
  9441. mtrace();
  9442. int result = FAIL;
  9443. int MaxKeySupported = 0;
  9444. int n_keys = 0;
  9445. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9446. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9447. json_object *GetConfiguration;
  9448. GetConfiguration = json_tokener_parse(payload);
  9449. if(!is_error(GetConfiguration))
  9450. {
  9451. // Optional data
  9452. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9453. {
  9454. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9455. {
  9456. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9457. n_keys = idx + 1;
  9458. }
  9459. }
  9460. }
  9461. json_object_put(GetConfiguration);
  9462. UnknownKeynum = 0;
  9463. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9464. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9465. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9466. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9467. if(n_keys != 0)
  9468. {
  9469. for(int i=0;i<n_keys;i++)
  9470. {
  9471. getKeyValue(requestKey[i]);
  9472. }
  9473. }
  9474. else
  9475. {
  9476. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9477. getKeyValue("");
  9478. }
  9479. processUnkownKey();
  9480. sendGetConfigurationConfirmation(uuid);
  9481. return result;
  9482. }
  9483. static char fnamePlusPath[100]={0};
  9484. static char fnamePWithNoPath[60]={0};
  9485. void checkUploadLog(void)
  9486. {
  9487. FILE *fp;
  9488. /* Open the command for reading. */
  9489. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9490. if (fp == NULL) {
  9491. DEBUG_WARN("Failed to run command\n" );
  9492. exit(1);
  9493. }
  9494. int ftppathlen = 0;
  9495. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9496. int i = 0;
  9497. /* Read the output a line at a time - output it. */
  9498. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9499. if(i==0)
  9500. {
  9501. ftppathlen = strlen(fnamePlusPath);
  9502. DEBUG_INFO("%s\n", fnamePlusPath);
  9503. fnamePlusPath[ftppathlen]='\0';
  9504. break;
  9505. }
  9506. i= i+1;
  9507. }
  9508. /* close */
  9509. pclose(fp);
  9510. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9511. {
  9512. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9513. {
  9514. fnamePlusPath[k]='\0';
  9515. }
  9516. }
  9517. i=1;
  9518. //char fname[60]={0};
  9519. while(i < ftppathlen)
  9520. {
  9521. int len=ftppathlen-i;
  9522. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9523. {
  9524. DEBUG_INFO("compare '/' all right\n");
  9525. break;
  9526. }
  9527. i=i+1;
  9528. }
  9529. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9530. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9531. fnamePWithNoPath[i+1] = '\0';
  9532. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9533. {
  9534. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9535. {
  9536. fnamePWithNoPath[j]='\0';
  9537. }
  9538. }
  9539. FILE* fp1 = fopen(fnamePlusPath, "r");
  9540. if (fp1)
  9541. {
  9542. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9543. // file exists
  9544. fclose(fp1);
  9545. }
  9546. else
  9547. {
  9548. // file doesn't exist
  9549. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9550. }
  9551. }
  9552. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9553. {
  9554. mtrace();
  9555. int result = FAIL;
  9556. time_t CurrentTime;
  9557. struct tm *tm;
  9558. pthread_t th_Status;
  9559. CurrentTime = time(NULL);
  9560. tm = localtime(&CurrentTime);
  9561. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9562. 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);
  9563. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9564. if(!interLock.isGetDiagnosticGoing)
  9565. {
  9566. interLock.isGetDiagnosticGoing = 1;
  9567. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9568. sleep(1);
  9569. }
  9570. else
  9571. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9572. return result;
  9573. }
  9574. void* GetDiagnosticsProcess(void* data)
  9575. {
  9576. pthread_detach(pthread_self());
  9577. mtrace();
  9578. int retriesInt=0, retryIntervalInt=0;
  9579. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9580. 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};
  9581. int port=0;
  9582. int isSuccess = FALSE;
  9583. char ftpbuf[200]={0};
  9584. char cmdBuf[2048];
  9585. struct tm *tmNow;
  9586. time_t CurrentTime;
  9587. struct tm tmStart;
  9588. struct tm tmStop;
  9589. CurrentTime = time(NULL);
  9590. tmNow=localtime(&CurrentTime);
  9591. uint16_t targetYear, targetMonth;
  9592. json_object *GetDiagnostics;
  9593. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9594. GetDiagnostics = json_tokener_parse(data);
  9595. if(!is_error(GetDiagnostics))
  9596. {
  9597. // Required data
  9598. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9599. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9600. // Optional data
  9601. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9602. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9603. else
  9604. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9605. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9606. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9607. else
  9608. retryIntervalInt = 30;
  9609. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9610. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9611. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9612. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9613. }
  9614. json_object_put(GetDiagnostics);
  9615. // Pack log to compress file
  9616. 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) &&
  9617. (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))
  9618. {
  9619. // Pack system log
  9620. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9621. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9622. targetYear = tmStart.tm_year;
  9623. targetMonth = tmStart.tm_mon;
  9624. do
  9625. {
  9626. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9627. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9628. if(targetMonth+1>=13)
  9629. {
  9630. targetYear += 1;
  9631. targetMonth = 1;
  9632. }
  9633. else
  9634. {
  9635. targetMonth += 1;
  9636. }
  9637. }while((targetYear < (tmNow->tm_year+1900)) ||
  9638. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9639. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9640. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9641. system(cmdBuf);
  9642. // Pack charging & event log
  9643. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9644. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9645. targetYear = tmStart.tm_year;
  9646. targetMonth = tmStart.tm_mon;
  9647. do
  9648. {
  9649. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9650. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9651. if(targetMonth+1>=13)
  9652. {
  9653. targetYear += 1;
  9654. targetMonth = 1;
  9655. }
  9656. else
  9657. {
  9658. targetMonth += 1;
  9659. }
  9660. }while((targetYear < (tmNow->tm_year+1900)) ||
  9661. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9662. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9663. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9664. system(cmdBuf);
  9665. // Combine log file
  9666. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9667. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9668. }
  9669. else
  9670. {
  9671. system("exec /root/logPackTools 'log' 6");
  9672. }
  9673. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9674. system(cmdBuf);
  9675. checkUploadLog();
  9676. //****************location*******************/
  9677. if(strcmp(locationstr,"")==0)
  9678. {
  9679. DEBUG_INFO("location is <Empty>!\n");
  9680. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9681. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9682. goto end;
  9683. }
  9684. memset(protocol, 0, ARRAY_SIZE(protocol));
  9685. memset(user, 0, ARRAY_SIZE(user) );
  9686. memset(password, 0, ARRAY_SIZE(password));
  9687. memset(host, 0, ARRAY_SIZE(host));
  9688. memset(path, 0, ARRAY_SIZE(path));
  9689. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9690. memset(host1, 0, ARRAY_SIZE(host1));
  9691. memset(path1, 0, ARRAY_SIZE(path1));
  9692. /*location: ftp://user:password@host:port/path*/
  9693. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9694. if((access(fnamePlusPath,F_OK))!=-1)
  9695. {
  9696. DEBUG_INFO("fnamePlusPath exist.\n");
  9697. }
  9698. else
  9699. {
  9700. DEBUG_INFO("fnamePlusPath not exist!\n");
  9701. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9702. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9703. goto end;
  9704. }
  9705. if(strchr(locationstr,'@')==NULL)
  9706. {
  9707. sscanf(locationstr,
  9708. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9709. protocol, host, &port, path);
  9710. strcpy(user,"anonymous");
  9711. strcpy(password,"");
  9712. }
  9713. else
  9714. {
  9715. //DEBUG_INFO("pch=%s\n", pch);
  9716. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9717. protocol, user, password, host, &port, path);
  9718. }
  9719. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9720. {
  9721. DEBUG_INFO("protocol is not ftp/http ! \n");
  9722. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9723. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9724. goto end;
  9725. }
  9726. if(strncmp(locationstr,"http", 4) == 0)
  9727. {
  9728. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9729. sprintf(ftppath,"/%s", path);
  9730. do
  9731. {
  9732. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9733. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9734. sleep(3);
  9735. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9736. if(!isSuccess)
  9737. {
  9738. DEBUG_INFO("Diagnostics fail.\n");
  9739. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9740. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9741. sleep(retryIntervalInt);
  9742. }
  9743. else
  9744. {
  9745. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9746. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9747. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9748. }
  9749. retriesInt--;
  9750. }while((isSuccess == 0)&&(retriesInt >= 0));
  9751. }
  9752. else
  9753. {
  9754. sscanf(host,"%[^/]%s",host1, path1);
  9755. if(strlen(path) > 0)
  9756. sprintf(ftppath,"/%s", path);
  9757. else
  9758. sprintf(ftppath,"/%s", path1);
  9759. int ftppathlen=strlen(ftppath);
  9760. int i=1;
  9761. char filenametemp[50];
  9762. while(i < ftppathlen)
  9763. {
  9764. int len=ftppathlen-i;
  9765. if(ftppath[len]== 47) // '/' ascll code: 47
  9766. {
  9767. DEBUG_INFO("find '/' all right\n");
  9768. break;
  9769. }
  9770. i=i+1;
  9771. }
  9772. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9773. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9774. filenametemp[i+1] = 0;
  9775. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9776. if(port == 0)
  9777. port = 21;
  9778. do
  9779. {
  9780. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9781. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9782. sleep(3);
  9783. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9784. if(!isSuccess)
  9785. {
  9786. DEBUG_INFO("Diagnostics fail.\n");
  9787. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9788. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9789. sleep(retryIntervalInt);
  9790. }
  9791. else
  9792. {
  9793. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9794. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9795. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9796. }
  9797. retriesInt--;
  9798. }while((!isSuccess)&&(retriesInt >= 0));
  9799. }
  9800. end:
  9801. system("rm -f /mnt/*");
  9802. sleep(5);
  9803. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9804. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9805. interLock.isGetDiagnosticGoing = 0;
  9806. pthread_exit(NULL);
  9807. }
  9808. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9809. {
  9810. mtrace();
  9811. int result = FAIL;
  9812. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9813. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9814. {
  9815. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9816. locallistVersion = -1;
  9817. }
  9818. else
  9819. {
  9820. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9821. OCPP_getListVerion();
  9822. }
  9823. //from db.OCPP_getListVerion
  9824. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9825. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9826. sendGetLocalListVersionConfirmation(uuid,"");
  9827. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9828. return result;
  9829. }
  9830. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9831. {
  9832. mtrace();
  9833. int result = FAIL;
  9834. int connectorIdInt=-1;
  9835. int tempIndex = 0;
  9836. int connectorIdIsNULL, chargingProfileIsNULL;
  9837. char comfirmstr[20]={0};
  9838. char cmdBuf[512];
  9839. json_object *RemoteStartTransaction;
  9840. FILE *fp;
  9841. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9842. if(server_pending == TRUE)
  9843. {
  9844. return 0;
  9845. }
  9846. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9847. RemoteStartTransaction = json_tokener_parse(payload);
  9848. if(!is_error(RemoteStartTransaction))
  9849. {
  9850. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9851. {
  9852. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9853. }
  9854. else
  9855. {
  9856. connectorIdIsNULL = TRUE;
  9857. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9858. {
  9859. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9860. {
  9861. connectorIdIsNULL = FALSE;
  9862. connectorIdInt = (gun_index+1);
  9863. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9864. break;
  9865. }
  9866. }
  9867. }
  9868. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9869. {
  9870. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9871. // Required data
  9872. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9873. // Optional data
  9874. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9875. {
  9876. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9877. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9878. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9879. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9880. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9881. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9882. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9883. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9884. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9885. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9886. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9887. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9888. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9889. {
  9890. 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")));
  9891. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9892. 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"));
  9893. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9894. 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"));
  9895. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9896. 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")));
  9897. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9898. {
  9899. 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++)
  9900. {
  9901. 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"));
  9902. 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"));
  9903. 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)
  9904. 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"));
  9905. }
  9906. }
  9907. }
  9908. }
  9909. else
  9910. {
  9911. chargingProfileIsNULL = TRUE;
  9912. }
  9913. }
  9914. }
  9915. else
  9916. {
  9917. connectorIdIsNULL = TRUE;
  9918. }
  9919. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9920. {
  9921. DEBUG_WARN("Connector id is NULL\n.");
  9922. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9923. goto end;
  9924. }
  9925. /*
  9926. enum _SYSTEM_STATUS
  9927. {
  9928. S_BOOTING = 0,
  9929. S_IDLE, = 1
  9930. S_AUTHORIZING, = 2
  9931. S_REASSIGN_CHECK, = 3
  9932. S_REASSIGN, = 4
  9933. S_PRECHARGE, = 5
  9934. S_PREPARING_FOR_EV, = 6
  9935. S_PREPARING_FOR_EVSE, = 7
  9936. S_CHARGING, = 8
  9937. S_TERMINATING, = 9
  9938. S_COMPLETE, = 10
  9939. S_ALARM, = 11
  9940. S_FAULT = 12
  9941. }
  9942. */
  9943. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9944. {
  9945. //check Transaction active
  9946. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9947. {
  9948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9949. {
  9950. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9951. }
  9952. else
  9953. {
  9954. tempIndex = connectorIdInt -1;
  9955. }
  9956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9957. {
  9958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9959. {
  9960. 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))
  9961. {
  9962. //Reserved
  9963. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9964. }
  9965. 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))
  9966. {
  9967. //Reserved
  9968. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9969. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9970. goto end;
  9971. }
  9972. else
  9973. {
  9974. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9975. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9976. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9977. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9978. {
  9979. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9981. goto end;
  9982. }
  9983. }//END FOR ELSE
  9984. }
  9985. }// END FOR CHAdeMO_QUANTITY
  9986. }
  9987. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9988. {
  9989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9990. {
  9991. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9992. }
  9993. else
  9994. {
  9995. tempIndex = connectorIdInt -1;
  9996. }
  9997. for (int index = 0; index < CCS_QUANTITY; index++)
  9998. {
  9999. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10000. {
  10001. 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))
  10002. {
  10003. //Reserved
  10004. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10005. }
  10006. 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))
  10007. {
  10008. //Reserved
  10009. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10010. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10011. goto end;
  10012. }
  10013. else
  10014. {
  10015. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10016. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10017. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10018. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10019. {
  10020. DEBUG_WARN("CCS connector not allow start\n.");
  10021. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10022. goto end;
  10023. }
  10024. }// END FOR ELSE
  10025. }
  10026. }// END FOR CCS_QUANTITY
  10027. }
  10028. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10029. {
  10030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10031. {
  10032. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10033. }
  10034. else
  10035. {
  10036. tempIndex = connectorIdInt -1;
  10037. }
  10038. for (int index = 0; index < GB_QUANTITY; index++)
  10039. {
  10040. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10041. {
  10042. 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))
  10043. {
  10044. //Reserved
  10045. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10046. }
  10047. 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))
  10048. {
  10049. //Reserved
  10050. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10051. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10052. goto end;
  10053. }
  10054. else
  10055. {
  10056. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10057. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10058. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10059. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10060. {
  10061. DEBUG_WARN("GB connector not allow start\n.");
  10062. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10063. goto end;
  10064. }
  10065. }// END FOR ELSE
  10066. }
  10067. } // END FOR GB_QUANTITY
  10068. }
  10069. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10070. {
  10071. tempIndex = connectorIdInt -1;
  10072. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10073. {
  10074. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10075. {
  10076. 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))
  10077. {
  10078. //Reserved
  10079. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10080. }
  10081. 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))
  10082. {
  10083. //Reserved
  10084. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10086. goto end;
  10087. }
  10088. else
  10089. {
  10090. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10091. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10092. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10093. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10094. {
  10095. DEBUG_WARN("GB connector not allow start\n.");
  10096. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10097. goto end;
  10098. }
  10099. }// END FOR ELSE
  10100. }
  10101. } // END FOR GB_QUANTITY
  10102. }
  10103. else
  10104. {
  10105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10106. {
  10107. tempIndex = 2;
  10108. }
  10109. else
  10110. {
  10111. tempIndex = connectorIdInt -1;
  10112. }
  10113. for (int index = 0; index < AC_QUANTITY; index++)
  10114. {
  10115. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10116. {
  10117. 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))
  10118. {
  10119. //Reserved
  10120. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10121. }
  10122. 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))
  10123. {
  10124. //Reserved
  10125. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10126. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10127. goto end;
  10128. }
  10129. else
  10130. {
  10131. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10132. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10133. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10134. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10135. {
  10136. DEBUG_WARN("AC connector not allow start\n.");
  10137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10138. goto end;
  10139. }
  10140. }//END FOR ELSE
  10141. }
  10142. }// END FOR AC_QUANTITY
  10143. }
  10144. if(chargingProfileIsNULL == FALSE)
  10145. {
  10146. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10147. {
  10148. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10150. //memset idTag
  10151. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10152. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10153. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10155. // Save profile to file
  10156. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10157. system(cmdBuf);
  10158. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10159. fp = fopen(cmdBuf, "w");
  10160. 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));
  10161. fclose(fp);
  10162. }
  10163. else
  10164. {
  10165. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10166. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10167. }
  10168. }
  10169. else
  10170. {
  10171. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10172. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10173. //memset idTag
  10174. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10175. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10176. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10178. }
  10179. }
  10180. else
  10181. {
  10182. DEBUG_WARN("Connector id over\n.");
  10183. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10184. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10185. }
  10186. end:
  10187. json_object_put(RemoteStartTransaction);
  10188. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10189. {
  10190. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10191. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10192. }
  10193. //OCPP send RemoteStartConfirmation by first.
  10194. sendRemoteStartConfirmation(uuid, comfirmstr);
  10195. return result;
  10196. }
  10197. int handleRemoteStartRequest(char *uuid, char *payload)
  10198. {
  10199. mtrace();
  10200. int result = PASS;
  10201. int connectorIdInt=-1;
  10202. int tempIndex = 0;
  10203. char comfirmstr[20]={0};
  10204. char cmdBuf[512];
  10205. json_object *RemoteStartTransaction;
  10206. FILE *fp;
  10207. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10208. if(server_pending == TRUE)
  10209. {
  10210. result = FAIL;
  10211. }
  10212. RemoteStartTransaction = json_tokener_parse(payload);
  10213. if(!is_error(RemoteStartTransaction))
  10214. {
  10215. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10216. {
  10217. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10218. }
  10219. else
  10220. {
  10221. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10222. {
  10223. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10224. {
  10225. connectorIdInt = (gun_index+1);
  10226. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10227. break;
  10228. }
  10229. }
  10230. }
  10231. if(connectorIdInt == 0)
  10232. {
  10233. DEBUG_WARN("Connector id shall not equal 0.\n");
  10234. result = FAIL;
  10235. }
  10236. else if(connectorIdInt == -1)
  10237. {
  10238. DEBUG_INFO("Connector id does not specific.\n");
  10239. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10240. {
  10241. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10242. // Required data
  10243. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10244. // Optional data
  10245. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10246. {
  10247. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10248. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10249. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10250. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10251. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10252. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10253. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10254. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10255. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10256. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10257. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10258. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10259. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10260. {
  10261. 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")));
  10262. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10263. 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"));
  10264. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10265. 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"));
  10266. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10267. 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")));
  10268. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10269. {
  10270. 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++)
  10271. {
  10272. 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"));
  10273. 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"));
  10274. 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)
  10275. 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"));
  10276. }
  10277. }
  10278. }
  10279. }
  10280. else
  10281. {
  10282. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10283. }
  10284. }
  10285. }
  10286. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10287. {
  10288. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10289. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10290. // Required data
  10291. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10292. // Optional data
  10293. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10294. {
  10295. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10296. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10297. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10298. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10299. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10300. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10301. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10302. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10303. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10304. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10305. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10306. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10307. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10308. {
  10309. 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")));
  10310. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10311. 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"));
  10312. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10313. 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"));
  10314. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10315. 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")));
  10316. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10317. {
  10318. 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++)
  10319. {
  10320. 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"));
  10321. 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"));
  10322. 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)
  10323. 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"));
  10324. }
  10325. }
  10326. }
  10327. }
  10328. else
  10329. {
  10330. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10331. }
  10332. }
  10333. else
  10334. {
  10335. DEBUG_WARN("Connector id is over maximun value.\n");
  10336. result = FAIL;
  10337. }
  10338. }
  10339. if(result == PASS)
  10340. {
  10341. if(connectorIdInt > 0)
  10342. {
  10343. //check Transaction active
  10344. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10345. {
  10346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10347. {
  10348. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10349. }
  10350. else
  10351. {
  10352. tempIndex = connectorIdInt -1;
  10353. }
  10354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10355. {
  10356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10357. {
  10358. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10359. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10360. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10361. {
  10362. //Reserved
  10363. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10364. }
  10365. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10366. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10367. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10368. {
  10369. //Reserved
  10370. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10371. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10372. goto end;
  10373. }
  10374. else
  10375. {
  10376. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10377. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10378. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10379. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10380. {
  10381. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10382. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10383. goto end;
  10384. }
  10385. }//END FOR ELSE
  10386. }
  10387. }// END FOR CHAdeMO_QUANTITY
  10388. }
  10389. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10390. {
  10391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10392. {
  10393. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10394. }
  10395. else
  10396. {
  10397. tempIndex = connectorIdInt -1;
  10398. }
  10399. for (int index = 0; index < CCS_QUANTITY; index++)
  10400. {
  10401. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10402. {
  10403. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10404. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10405. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10406. {
  10407. //Reserved
  10408. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10409. }
  10410. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10411. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10412. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10413. {
  10414. //Reserved
  10415. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10416. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10417. goto end;
  10418. }
  10419. else
  10420. {
  10421. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10422. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10423. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10424. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10425. {
  10426. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10427. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10428. goto end;
  10429. }
  10430. }// END FOR ELSE
  10431. }
  10432. }// END FOR CCS_QUANTITY
  10433. }
  10434. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10435. {
  10436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10437. {
  10438. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10439. }
  10440. else
  10441. {
  10442. tempIndex = connectorIdInt -1;
  10443. }
  10444. for (int index = 0; index < GB_QUANTITY; index++)
  10445. {
  10446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10447. {
  10448. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10449. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10450. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10451. {
  10452. //Reserved
  10453. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10454. }
  10455. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10456. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10457. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10458. {
  10459. //Reserved
  10460. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10461. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10462. goto end;
  10463. }
  10464. else
  10465. {
  10466. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10467. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10468. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10469. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10470. {
  10471. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10472. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10473. goto end;
  10474. }
  10475. }// END FOR ELSE
  10476. }
  10477. } // END FOR GB_QUANTITY
  10478. }
  10479. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10480. {
  10481. tempIndex = connectorIdInt -1;
  10482. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10483. {
  10484. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10485. {
  10486. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10487. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10488. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10489. {
  10490. //Reserved
  10491. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10492. }
  10493. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10494. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10495. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10496. {
  10497. //Reserved
  10498. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10499. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10500. goto end;
  10501. }
  10502. else
  10503. {
  10504. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10505. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10506. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10507. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10508. {
  10509. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10510. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10511. goto end;
  10512. }
  10513. }// END FOR ELSE
  10514. }
  10515. } // END FOR GB_QUANTITY
  10516. }
  10517. else
  10518. {
  10519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10520. {
  10521. tempIndex = 2;
  10522. }
  10523. else
  10524. {
  10525. tempIndex = connectorIdInt -1;
  10526. }
  10527. for (int index = 0; index < AC_QUANTITY; index++)
  10528. {
  10529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10530. {
  10531. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10532. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10533. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10534. {
  10535. //Reserved
  10536. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10537. }
  10538. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10539. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10540. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10541. {
  10542. //Reserved
  10543. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10544. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10545. goto end;
  10546. }
  10547. else
  10548. {
  10549. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10550. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10551. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10552. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10553. {
  10554. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10555. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10556. goto end;
  10557. }
  10558. }//END FOR ELSE
  10559. }
  10560. }// END FOR AC_QUANTITY
  10561. }
  10562. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10563. {
  10564. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10565. {
  10566. // Save profile to file
  10567. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10568. system(cmdBuf);
  10569. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10570. fp = fopen(cmdBuf, "w");
  10571. 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));
  10572. fclose(fp);
  10573. }
  10574. else
  10575. {
  10576. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10577. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10578. goto end;
  10579. }
  10580. }
  10581. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10582. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10583. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10584. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10585. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10587. }
  10588. else
  10589. {
  10590. uint8_t isHasIdleConnector = FALSE;
  10591. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10592. {
  10593. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10594. {
  10595. isHasIdleConnector = TRUE;
  10596. break;
  10597. }
  10598. }
  10599. if(isHasIdleConnector == TRUE)
  10600. {
  10601. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10602. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10603. {
  10604. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10605. {
  10606. // Save profile to file
  10607. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10608. system(cmdBuf);
  10609. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10610. fp = fopen(cmdBuf, "w");
  10611. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10612. fclose(fp);
  10613. refreshStartTimer(&clientTime.RemoteStartWait);
  10614. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10615. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10616. }
  10617. else
  10618. {
  10619. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10620. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10621. }
  10622. }
  10623. else
  10624. {
  10625. refreshStartTimer(&clientTime.RemoteStartWait);
  10626. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10627. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10628. }
  10629. }
  10630. else
  10631. {
  10632. DEBUG_INFO("There is not any connector is idle.\n");
  10633. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10634. }
  10635. }
  10636. }
  10637. else
  10638. {
  10639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10640. }
  10641. end:
  10642. json_object_put(RemoteStartTransaction);
  10643. sendRemoteStartConfirmation(uuid, comfirmstr);
  10644. return result;
  10645. }
  10646. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10647. {
  10648. mtrace();
  10649. int result = FAIL;
  10650. int match = FALSE;
  10651. int GunNO = 0;
  10652. int tempIndex = 0;
  10653. int transactionIdInt=0;
  10654. int transactionIdIsNULL= TRUE;
  10655. char comfirmstr[20];
  10656. json_object *RemoteStopTransaction;
  10657. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10658. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10659. if(server_pending == TRUE)
  10660. {
  10661. return 0;
  10662. }
  10663. RemoteStopTransaction = json_tokener_parse(payload);
  10664. if(!is_error(RemoteStopTransaction))
  10665. {
  10666. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10667. {
  10668. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10669. transactionIdIsNULL = FALSE;
  10670. }
  10671. }
  10672. json_object_put(RemoteStopTransaction);
  10673. if(transactionIdIsNULL == FALSE)
  10674. {
  10675. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10676. {
  10677. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10678. {
  10679. //check Transaction active
  10680. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10681. {
  10682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10683. {
  10684. tempIndex = ((gun_index==2) ? 1: 0);
  10685. }
  10686. else
  10687. {
  10688. tempIndex = gun_index;
  10689. }
  10690. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10691. {
  10692. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10693. {
  10694. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10695. {
  10696. match = TRUE;
  10697. GunNO = gun_index;
  10698. }
  10699. }
  10700. }// END FOR CHAdeMO_QUANTITY
  10701. }
  10702. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10703. {
  10704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10705. {
  10706. tempIndex = ((gun_index==2) ? 1: 0);
  10707. }
  10708. else
  10709. {
  10710. tempIndex = gun_index;
  10711. }
  10712. for (int index = 0; index < CCS_QUANTITY; index++)
  10713. {
  10714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10715. {
  10716. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10717. {
  10718. match = TRUE;
  10719. GunNO = gun_index;
  10720. }
  10721. }
  10722. }// END FOR CCS_QUANTITY
  10723. }
  10724. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10725. {
  10726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10727. {
  10728. tempIndex = ((gun_index==2) ? 1: 0);
  10729. }
  10730. else
  10731. {
  10732. tempIndex = gun_index;
  10733. }
  10734. for (int index = 0; index < GB_QUANTITY; index++)
  10735. {
  10736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10737. {
  10738. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10739. {
  10740. match = TRUE;
  10741. GunNO = gun_index;
  10742. }
  10743. }
  10744. }// END FOR GB_QUANTITY
  10745. }
  10746. else if(gunType[gun_index] == GUN_TYPE_DO)
  10747. {
  10748. tempIndex = gun_index;
  10749. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10750. {
  10751. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10752. {
  10753. 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
  10754. {
  10755. match = TRUE;
  10756. GunNO = gun_index;
  10757. }
  10758. }
  10759. }// END FOR GB_QUANTITY
  10760. }
  10761. else
  10762. {
  10763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10764. {
  10765. tempIndex = 2;
  10766. }
  10767. else
  10768. {
  10769. tempIndex = gun_index;
  10770. }
  10771. for (int index = 0; index < AC_QUANTITY; index++)
  10772. {
  10773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10774. {
  10775. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10776. {
  10777. match = TRUE;
  10778. GunNO = gun_index;
  10779. }
  10780. }
  10781. }// END FOR CHAdeMO_QUANTITY
  10782. } // END FOR AC ELSE
  10783. }// CHECK IF ResponseTransactionId == transactionIdInt
  10784. }//END FOR
  10785. if( match == TRUE)
  10786. {
  10787. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10788. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10789. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10790. }
  10791. else
  10792. {
  10793. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10794. }
  10795. }
  10796. else
  10797. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10798. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10799. return result;
  10800. }
  10801. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10802. {
  10803. mtrace();
  10804. int result = FAIL;
  10805. int connectorIdInt=0, reservationIdInt=0;
  10806. int tempIndex = 0;
  10807. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10808. char comfirmstr[20]={0};
  10809. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10810. int c = 0;
  10811. char *loc;
  10812. //char *ptr;
  10813. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10814. strcpy(sstrtemp, stringtrimspace(payload));
  10815. //***(1)connectorId ****/
  10816. c=0;
  10817. loc = strstr(sstrtemp, "connectorId");
  10818. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10819. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10820. {
  10821. sstr[c] = loc[strlen("connectorId")+2+c];
  10822. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10823. c++;
  10824. }
  10825. sstr[c] = '\0';
  10826. connectorIdInt = atoi(sstr);
  10827. //***(2)expiryDate ****/
  10828. loc = strstr(sstrtemp, "expiryDate");
  10829. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10830. c = 0;
  10831. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10832. {
  10833. sstr[c] = loc[3+strlen("expiryDate")+c];
  10834. c++;
  10835. }
  10836. sstr[c] = '\0';
  10837. strcpy(expiryDatestr, sstr);
  10838. //***(3)idTag ****/
  10839. loc = strstr(sstrtemp, "idTag");
  10840. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10841. c = 0;
  10842. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10843. {
  10844. sstr[c] = loc[3+strlen("idTag")+c];
  10845. c++;
  10846. }
  10847. sstr[c] = '\0';
  10848. strcpy(idTagstr, sstr);
  10849. //***(4)parentIdTag ****/
  10850. loc = strstr(sstrtemp, "parentIdTag");
  10851. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10852. c = 0;
  10853. if(loc == NULL)
  10854. {
  10855. strcpy(parentIdTagstr, "");
  10856. }
  10857. else
  10858. {
  10859. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10860. {
  10861. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10862. c++;
  10863. }
  10864. sstr[c] = '\0';
  10865. strcpy(parentIdTagstr, sstr);
  10866. }
  10867. //***(5)reservationId ****/
  10868. c=0;
  10869. loc = strstr(sstrtemp, "reservationId");
  10870. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10871. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10872. {
  10873. sstr[c] = loc[strlen("reservationId")+2+c];
  10874. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10875. c++;
  10876. }
  10877. sstr[c] = '\0';
  10878. reservationIdInt = atoi(sstr);
  10879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10880. /*
  10881. enum SYSTEM_STATUS
  10882. {
  10883. SYS_MODE_BOOTING = 0,
  10884. SYS_MODE_IDLE = 1,
  10885. SYS_MODE_AUTHORIZING = 2,
  10886. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10887. SYS_MODE_REASSIGN = 4,
  10888. SYS_MODE_PREPARING = 5,
  10889. SYS_MODE_PREPARE_FOR_EV = 6,
  10890. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10891. SYS_MODE_CHARGING = 8,
  10892. SYS_MODE_TERMINATING = 9,
  10893. SYS_MODE_COMPLETE = 10,
  10894. SYS_MODE_ALARM = 11,
  10895. SYS_MODE_FAULT = 12,
  10896. SYS_MODE_RESERVATION = 13,
  10897. SYS_MODE_BOOKING = 14,
  10898. SYS_MODE_MAINTAIN = 15,
  10899. SYS_MODE_DEBUG = 16,
  10900. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10901. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10902. SYS_MODE_UPDATE = 19
  10903. };
  10904. */
  10905. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10906. {
  10907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10908. goto end;
  10909. }
  10910. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10911. {
  10912. //check Transaction active
  10913. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10914. {
  10915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10916. {
  10917. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10918. }
  10919. else
  10920. {
  10921. tempIndex = connectorIdInt -1;
  10922. }
  10923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10924. {
  10925. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10926. {
  10927. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10928. {
  10929. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10930. {
  10931. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10932. {
  10933. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10935. }
  10936. 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'))
  10937. {
  10938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10939. }
  10940. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10941. {
  10942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10943. }
  10944. else
  10945. {
  10946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10947. }
  10948. }
  10949. 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
  10950. {
  10951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10952. }
  10953. }
  10954. else
  10955. {
  10956. //replace reservation
  10957. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10959. }
  10960. }
  10961. } // END FOR CHAdeMO_QUANTITY
  10962. }
  10963. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10964. {
  10965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10966. {
  10967. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10968. }
  10969. else
  10970. {
  10971. tempIndex = connectorIdInt -1;
  10972. }
  10973. for (int index = 0; index < CCS_QUANTITY; index++)
  10974. {
  10975. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10976. {
  10977. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10978. {
  10979. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10980. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10981. {
  10982. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10983. {
  10984. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10986. }
  10987. 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'))
  10988. {
  10989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10990. }
  10991. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10992. {
  10993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10994. }
  10995. else
  10996. {
  10997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10998. }
  10999. }
  11000. 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
  11001. {
  11002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11003. }
  11004. }
  11005. else
  11006. {
  11007. //replace reservation
  11008. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11010. }
  11011. }
  11012. } // END FOR CCS_QUANTITY
  11013. }
  11014. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11015. {
  11016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11017. {
  11018. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11019. }
  11020. else
  11021. {
  11022. tempIndex = connectorIdInt -1;
  11023. }
  11024. for (int index = 0; index < GB_QUANTITY; index++)
  11025. {
  11026. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11027. {
  11028. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11029. {
  11030. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11031. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11032. {
  11033. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11034. {
  11035. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11037. }
  11038. 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'))
  11039. {
  11040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11041. }
  11042. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11043. {
  11044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11045. }
  11046. else
  11047. {
  11048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11049. }
  11050. }
  11051. 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
  11052. {
  11053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11054. }
  11055. }
  11056. else
  11057. {
  11058. //replace reservation
  11059. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11061. }
  11062. }
  11063. }// END FOR GB_QUANTITY
  11064. }
  11065. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11066. {
  11067. tempIndex = connectorIdInt -1;
  11068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11069. {
  11070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11071. {
  11072. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11073. {
  11074. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11075. 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
  11076. {
  11077. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11078. {
  11079. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11081. }
  11082. 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'))
  11083. {
  11084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11085. }
  11086. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11087. {
  11088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11089. }
  11090. else
  11091. {
  11092. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11093. }
  11094. }
  11095. 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
  11096. {
  11097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11098. }
  11099. }
  11100. else
  11101. {
  11102. //replace reservation
  11103. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11105. }
  11106. }
  11107. }// END FOR GB_QUANTITY
  11108. }
  11109. else
  11110. {
  11111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11112. {
  11113. tempIndex = 2;
  11114. }
  11115. else
  11116. {
  11117. tempIndex = (connectorIdInt -1);
  11118. }
  11119. for (int index = 0; index < AC_QUANTITY; index++)
  11120. {
  11121. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11122. {
  11123. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11124. {
  11125. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11126. {
  11127. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11128. {
  11129. 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))
  11130. {
  11131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11132. }
  11133. else
  11134. {
  11135. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11137. }
  11138. }
  11139. 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'))
  11140. {
  11141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11142. }
  11143. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11144. {
  11145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11146. }
  11147. else
  11148. {
  11149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11150. }
  11151. }
  11152. 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
  11153. {
  11154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11155. }
  11156. }
  11157. else
  11158. {
  11159. //replace reservation
  11160. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11162. }
  11163. }
  11164. } // END FOR AC_QUANTITY
  11165. }
  11166. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11167. }
  11168. else if(connectorIdInt == 0)
  11169. {
  11170. //check Transaction active
  11171. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11172. {
  11173. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11174. {
  11175. 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'))
  11176. {
  11177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11178. goto end;
  11179. }
  11180. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11181. {
  11182. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11183. goto end;
  11184. }
  11185. 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
  11186. {
  11187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11188. goto end;
  11189. }
  11190. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11191. {
  11192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11193. goto end;
  11194. }
  11195. }
  11196. }// END FOR CHAdeMO_QUANTITY
  11197. for (int index = 0; index < CCS_QUANTITY; index++)
  11198. {
  11199. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11200. {
  11201. 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'))
  11202. {
  11203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11204. goto end;
  11205. }
  11206. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11207. {
  11208. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11209. goto end;
  11210. }
  11211. 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
  11212. {
  11213. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11214. goto end;
  11215. }
  11216. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11217. {
  11218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11219. goto end;
  11220. }
  11221. }
  11222. } // END FOR CCS_QUANTITY
  11223. for (int index = 0; index < GB_QUANTITY; index++)
  11224. {
  11225. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11226. {
  11227. 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'))
  11228. {
  11229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11230. goto end;
  11231. }
  11232. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11233. {
  11234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11235. goto end;
  11236. }
  11237. 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
  11238. {
  11239. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11240. goto end;
  11241. }
  11242. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11243. {
  11244. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11245. goto end;
  11246. }
  11247. }
  11248. } // END FOR GB_QUANTITY
  11249. for (int index = 0; index < AC_QUANTITY; index++)
  11250. {
  11251. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11252. {
  11253. 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'))
  11254. {
  11255. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11256. goto end;
  11257. }
  11258. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11259. {
  11260. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11261. goto end;
  11262. }
  11263. 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
  11264. {
  11265. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11266. goto end;
  11267. }
  11268. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11269. {
  11270. 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))
  11271. {
  11272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11273. goto end;
  11274. }
  11275. }
  11276. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11277. {
  11278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11279. goto end;
  11280. }
  11281. }
  11282. }// END FOR AC_QUANTITY
  11283. //The connectorId is 0
  11284. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11285. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11286. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11287. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11288. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11289. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11290. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11291. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11292. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11293. result = TRUE;
  11294. return result;
  11295. }
  11296. else
  11297. {
  11298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11299. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11300. }
  11301. if(strcmp(comfirmstr,"Accepted") == 0)
  11302. {
  11303. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11304. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11305. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11306. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11307. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11308. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11309. result = TRUE;
  11310. return result;
  11311. }
  11312. end:
  11313. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11314. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11315. return result;
  11316. }
  11317. int handleResetRequest(char *uuid, char *payload)
  11318. {
  11319. mtrace();
  11320. int result = FAIL;
  11321. char sstr[10]={0},sstrtemp[30]={ 0 };
  11322. char typestr[10]={0};
  11323. char comfirmstr[20]={0};
  11324. int c = 0;
  11325. char *loc;
  11326. DEBUG_INFO("handleResetRequest...\n");
  11327. strcpy(sstrtemp, stringtrimspace(payload));
  11328. loc = strstr(sstrtemp, "type");
  11329. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11330. c = 0;
  11331. while (loc[3+strlen("type")+c] != '\"')
  11332. {
  11333. sstr[c] = loc[3+strlen("type")+c];
  11334. c++;
  11335. }
  11336. sstr[c] = '\0';
  11337. strcpy(typestr,sstr);
  11338. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11339. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11340. {
  11341. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11342. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11343. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11344. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11345. }
  11346. else
  11347. {
  11348. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11349. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11350. result = PASS;
  11351. }
  11352. sendResetConfirmation(uuid, comfirmstr);
  11353. return result;
  11354. }
  11355. int handleSendLocalListRequest(char *uuid, char *payload)
  11356. {
  11357. mtrace();
  11358. int result = FAIL;
  11359. char comfirmstr[20];
  11360. int checkState_Faulted = FALSE;
  11361. json_object *SendLocalList;
  11362. DEBUG_INFO("handleSendLocalListRequest...\n");
  11363. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11364. {
  11365. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11366. goto end;
  11367. }
  11368. //check Charge Point state
  11369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11370. {
  11371. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11372. {
  11373. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11374. }
  11375. }
  11376. for (int index = 0; index < CCS_QUANTITY; index++)
  11377. {
  11378. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11379. {
  11380. checkState_Faulted = TRUE; //OCPP Status
  11381. }
  11382. }
  11383. for (int index = 0; index < GB_QUANTITY; index++)
  11384. {
  11385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11386. {
  11387. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11388. }
  11389. }
  11390. //check Charge Point state
  11391. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11392. {
  11393. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11394. {
  11395. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11396. }
  11397. }
  11398. //check Charge Point state
  11399. for (int index = 0; index < AC_QUANTITY; index++)
  11400. {
  11401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11402. {
  11403. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11404. }
  11405. }
  11406. if(checkState_Faulted == TRUE)
  11407. {
  11408. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11409. goto end;
  11410. }
  11411. // Parsing payload
  11412. SendLocalList = json_tokener_parse(payload);
  11413. if(!is_error(SendLocalList))
  11414. {
  11415. // Required data
  11416. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11417. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11418. // Optional data
  11419. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11420. {
  11421. //Check UpdateType
  11422. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11423. {
  11424. //Local list full update
  11425. DEBUG_INFO("Local list full update.\n");
  11426. OCPP_getListVerion();
  11427. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11428. {
  11429. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11430. goto end;
  11431. }
  11432. OCPP_cleanLocalList();
  11433. }
  11434. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11435. {
  11436. //Local list different update
  11437. DEBUG_INFO("Local list different update.\n");
  11438. OCPP_getListVerion();
  11439. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11440. {
  11441. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11442. goto end;
  11443. }
  11444. }
  11445. else
  11446. {
  11447. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11448. goto end;
  11449. }
  11450. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11451. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11452. {
  11453. 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")));
  11454. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11455. {
  11456. 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")));
  11457. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11458. 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")));
  11459. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11460. 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")));
  11461. }
  11462. // Add to db
  11463. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11464. {
  11465. //Local list full update
  11466. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11467. idx,
  11468. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11469. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11470. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11471. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11472. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11473. // update list
  11474. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11475. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11476. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11477. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11478. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11479. }
  11480. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11481. {
  11482. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11483. idx,
  11484. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11485. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11486. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11487. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11488. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11489. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11490. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11491. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11492. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11493. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11494. }
  11495. }
  11496. }
  11497. else
  11498. {
  11499. //Check UpdateType
  11500. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11501. {
  11502. //Local list full update
  11503. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11504. OCPP_cleanLocalList();
  11505. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11506. goto end;
  11507. }
  11508. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11509. {
  11510. //Local list different update
  11511. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11512. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11513. goto end;
  11514. }
  11515. }
  11516. result = PASS;
  11517. }
  11518. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11519. end:
  11520. json_object_put(SendLocalList);
  11521. sendSendLocalListConfirmation(uuid, comfirmstr);
  11522. return result;
  11523. }
  11524. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11525. {
  11526. mtrace();
  11527. int result = FAIL;
  11528. struct StructSetChargingProfile SetProfileReq = {0};
  11529. int tempchargingProfileIdInt;
  11530. int tempstackLevelInt;
  11531. int chargingSchedulePeriodCount = 0;
  11532. char comfirmstr[20]={0};
  11533. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11534. char rmFileCmd[128]={0};
  11535. int profileQuantity = 0;
  11536. int isReplaceable = FALSE;
  11537. json_object *SetChargingProfile;
  11538. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11539. SetChargingProfile = json_tokener_parse(payload);
  11540. if(!is_error(SetChargingProfile))
  11541. {
  11542. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11543. {
  11544. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11545. }
  11546. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11547. {
  11548. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11549. {
  11550. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11551. }
  11552. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11553. {
  11554. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11555. }
  11556. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11557. {
  11558. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11559. }
  11560. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11561. {
  11562. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11563. }
  11564. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11565. {
  11566. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11567. }
  11568. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11569. {
  11570. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11571. }
  11572. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11573. {
  11574. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11575. }
  11576. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11577. {
  11578. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11579. }
  11580. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11581. {
  11582. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11583. {
  11584. 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")));
  11585. }
  11586. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11587. {
  11588. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11589. }
  11590. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11591. {
  11592. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11593. }
  11594. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11595. {
  11596. 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")));
  11597. }
  11598. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11599. {
  11600. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11601. if(chargingSchedulePeriodCount <= 10)
  11602. {
  11603. 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++)
  11604. {
  11605. 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)
  11606. {
  11607. 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"));
  11608. }
  11609. 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)
  11610. {
  11611. 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"));
  11612. }
  11613. 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)
  11614. {
  11615. 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"));
  11616. }
  11617. }
  11618. }
  11619. }
  11620. }
  11621. }
  11622. }
  11623. // Profile periods quantity check
  11624. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11625. {
  11626. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11627. goto end;
  11628. }
  11629. // Check invalid limit
  11630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11631. {
  11632. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11633. {
  11634. 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)))) ||
  11635. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11636. {
  11637. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11638. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11639. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11640. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11641. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11642. goto end;
  11643. }
  11644. }
  11645. }
  11646. else
  11647. {
  11648. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11649. {
  11650. 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))
  11651. {
  11652. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11653. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11654. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11655. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11656. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11657. goto end;
  11658. }
  11659. }
  11660. }
  11661. // Profile purpose info check
  11662. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11663. {
  11664. FILE *fp;
  11665. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11666. if(SetProfileReq.ConnectorId != 0)
  11667. {
  11668. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11669. goto end;
  11670. }
  11671. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11672. if (!fp)
  11673. {
  11674. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11675. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11676. }
  11677. else
  11678. {
  11679. char *line = NULL;
  11680. size_t len = 0;
  11681. while(getline(&line, &len, fp) != -1)
  11682. {
  11683. json_object *obj = NULL;
  11684. obj = json_tokener_parse(line);
  11685. if(is_error(obj))
  11686. {
  11687. DEBUG_ERROR("Parse txProfile from file error.\n");
  11688. }
  11689. else
  11690. {
  11691. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11692. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11693. {
  11694. profileQuantity += 1;
  11695. }
  11696. else
  11697. isReplaceable = TRUE;
  11698. }
  11699. }
  11700. }
  11701. fclose(fp);
  11702. }
  11703. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11704. {
  11705. FILE *fp;
  11706. char filename[128]={0};
  11707. int tmpProfileQuantity;
  11708. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11709. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11710. {
  11711. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11712. goto end;
  11713. }
  11714. if(SetProfileReq.ConnectorId == 0)
  11715. {
  11716. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11717. {
  11718. tmpProfileQuantity = 0;
  11719. memset(filename, 0, ARRAY_SIZE(filename));
  11720. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11721. fp = fopen(filename, "r");
  11722. if (!fp)
  11723. {
  11724. DEBUG_INFO("%s does not create.\n", filename);
  11725. fp = fopen(filename, "w+");
  11726. }
  11727. else
  11728. {
  11729. char *line = NULL;
  11730. size_t len = 0;
  11731. while(getline(&line, &len, fp) != -1)
  11732. {
  11733. json_object *obj = NULL;
  11734. obj = json_tokener_parse(line);
  11735. if(is_error(obj))
  11736. {
  11737. DEBUG_ERROR("Parse txProfile from file error.\n");
  11738. }
  11739. else
  11740. {
  11741. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11742. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11743. {
  11744. tmpProfileQuantity += 1;
  11745. }
  11746. else
  11747. isReplaceable = TRUE;
  11748. }
  11749. }
  11750. }
  11751. fclose(fp);
  11752. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11753. }
  11754. }
  11755. else
  11756. {
  11757. memset(filename, 0, ARRAY_SIZE(filename));
  11758. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11759. fp = fopen(filename, "r");
  11760. if (!fp)
  11761. {
  11762. DEBUG_INFO("%s does not create.\n", filename);
  11763. fp = fopen(filename, "w+");
  11764. }
  11765. else
  11766. {
  11767. char *line = NULL;
  11768. size_t len = 0;
  11769. while(getline(&line, &len, fp) != -1)
  11770. {
  11771. json_object *obj = NULL;
  11772. obj = json_tokener_parse(line);
  11773. if(is_error(obj))
  11774. {
  11775. DEBUG_ERROR("Parse txProfile from file error.\n");
  11776. }
  11777. else
  11778. {
  11779. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11780. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11781. {
  11782. profileQuantity += 1;
  11783. }
  11784. else
  11785. isReplaceable = TRUE;
  11786. }
  11787. }
  11788. }
  11789. fclose(fp);
  11790. }
  11791. }
  11792. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11793. {
  11794. int isMatchTransactiodId= FALSE;
  11795. FILE *fp;
  11796. char filename[128]={0};
  11797. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11798. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11799. if(SetProfileReq.ConnectorId == 0)
  11800. {
  11801. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11802. goto end;
  11803. }
  11804. int tempIndex = 0;
  11805. //check Transaction active
  11806. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11807. {
  11808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11809. {
  11810. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11811. }
  11812. else
  11813. {
  11814. tempIndex = SetProfileReq.ConnectorId -1;
  11815. }
  11816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11817. {
  11818. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11819. {
  11820. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11821. {
  11822. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11823. {
  11824. isMatchTransactiodId = TRUE;
  11825. break;
  11826. }
  11827. }
  11828. }
  11829. }
  11830. }
  11831. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11832. {
  11833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11834. {
  11835. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11836. }
  11837. else
  11838. {
  11839. tempIndex = SetProfileReq.ConnectorId -1;
  11840. }
  11841. for (int index = 0; index < CCS_QUANTITY; index++)
  11842. {
  11843. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11844. {
  11845. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11846. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11847. {
  11848. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11849. {
  11850. isMatchTransactiodId = TRUE;
  11851. break;
  11852. }
  11853. }
  11854. }
  11855. }
  11856. }
  11857. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11858. {
  11859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11860. {
  11861. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11862. }
  11863. else
  11864. {
  11865. tempIndex = SetProfileReq.ConnectorId -1;
  11866. }
  11867. for (int index = 0; index < GB_QUANTITY; index++)
  11868. {
  11869. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11870. {
  11871. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11872. {
  11873. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11874. {
  11875. isMatchTransactiodId = TRUE;
  11876. break;
  11877. }
  11878. }
  11879. }
  11880. }
  11881. }
  11882. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11883. {
  11884. tempIndex = SetProfileReq.ConnectorId -1;
  11885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11886. {
  11887. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11888. {
  11889. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11890. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11891. {
  11892. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11893. {
  11894. isMatchTransactiodId = TRUE;
  11895. break;
  11896. }
  11897. }
  11898. }
  11899. }
  11900. }
  11901. else
  11902. {
  11903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11904. {
  11905. tempIndex = 2;
  11906. }
  11907. else
  11908. {
  11909. tempIndex = (SetProfileReq.ConnectorId -1);
  11910. }
  11911. for (int index = 0; index < AC_QUANTITY; index++)
  11912. {
  11913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11914. {
  11915. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11916. {
  11917. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11918. {
  11919. isMatchTransactiodId = TRUE;
  11920. break;
  11921. }
  11922. }
  11923. }
  11924. }
  11925. }
  11926. //check Transaction active
  11927. if(isMatchTransactiodId == FALSE)
  11928. {
  11929. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11930. goto end;
  11931. }
  11932. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11933. {
  11934. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11935. goto end;
  11936. }
  11937. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11938. fp = fopen(filename, "r");
  11939. if (!fp)
  11940. {
  11941. DEBUG_INFO("%s does not create.\n", filename);
  11942. fp = fopen(filename, "w+");
  11943. }
  11944. else
  11945. {
  11946. char *line = NULL;
  11947. size_t len = 0;
  11948. while(getline(&line, &len, fp) != -1)
  11949. {
  11950. json_object *obj = NULL;
  11951. obj = json_tokener_parse(line);
  11952. if(is_error(obj))
  11953. {
  11954. DEBUG_ERROR("Parse txProfile from file error.\n");
  11955. }
  11956. else
  11957. {
  11958. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11959. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11960. {
  11961. profileQuantity += 1;
  11962. }
  11963. else
  11964. isReplaceable = TRUE;
  11965. }
  11966. }
  11967. }
  11968. fclose(fp);
  11969. }
  11970. // Check ChargeProfileMaxStackLevel
  11971. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11972. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11973. {
  11974. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11975. goto end;
  11976. }
  11977. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11978. {
  11979. FILE *fp;
  11980. char dataLine[4096]={0};
  11981. char fnametemp[128]={0};
  11982. int tmpProfileQuantity;
  11983. //Check ChargePointMaxProfile.json exit
  11984. profileQuantity = 0;
  11985. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11986. {
  11987. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11988. //Check Charging Profile Count
  11989. tmpProfileQuantity = 0;
  11990. while(fscanf(fp, "%s", dataLine) != EOF)
  11991. {
  11992. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11993. {
  11994. profileQuantity += 1;
  11995. tmpProfileQuantity += 1;
  11996. }
  11997. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11998. }
  11999. fclose(fp);
  12000. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12001. }
  12002. //Check TxDefaultProfile_%d.json
  12003. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12004. {
  12005. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12006. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12007. if((access(fnametemp,F_OK))!=-1)
  12008. {
  12009. fp = fopen(fnametemp, "r");
  12010. //Check Charging Profile Count
  12011. tmpProfileQuantity = 0;
  12012. while(fscanf(fp, "%s", dataLine) != EOF)
  12013. {
  12014. //DEBUG_INFO("word=%s\n",word);
  12015. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12016. {
  12017. profileQuantity += 1;
  12018. tmpProfileQuantity += 1;
  12019. }
  12020. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12021. }
  12022. fclose(fp);
  12023. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12024. }
  12025. }
  12026. //Check TxProfile_%d.json
  12027. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12028. {
  12029. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12030. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12031. if((access(fnametemp,F_OK))!=-1)
  12032. {
  12033. fp = fopen(fnametemp, "r");
  12034. //Check Charging Profile Count
  12035. tmpProfileQuantity = 0;
  12036. while(fscanf(fp, "%s", dataLine) != EOF)
  12037. {
  12038. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12039. {
  12040. profileQuantity += 1;
  12041. tmpProfileQuantity += 1;
  12042. }
  12043. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12044. }
  12045. fclose(fp);
  12046. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12047. }
  12048. }
  12049. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12050. if((profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12051. {
  12052. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12053. goto end;
  12054. }
  12055. }
  12056. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12057. //**********************************Write to File********************************************************/
  12058. {
  12059. FILE *infile;
  12060. FILE *outfile;
  12061. char dataLine[4096]={0};
  12062. char filename[128]={0};
  12063. int chkChar=0;
  12064. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12065. {
  12066. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12067. {
  12068. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12069. }
  12070. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12071. {
  12072. if(SetProfileReq.ConnectorId==0)
  12073. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12074. else
  12075. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12076. }
  12077. else
  12078. {
  12079. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12080. }
  12081. infile = fopen (filename, "r");
  12082. outfile = fopen (tempfile, "w");
  12083. chkChar = fgetc(infile);
  12084. rewind(infile);
  12085. if(chkChar == EOF)
  12086. {
  12087. // Profile is empty
  12088. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12089. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12090. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12091. fclose(infile);
  12092. fclose(outfile);
  12093. sprintf(rmFileCmd,"rm -f %s",filename);
  12094. system(rmFileCmd);
  12095. rename(tempfile, filename);
  12096. }
  12097. else
  12098. {
  12099. // Profile is not empty
  12100. int ChargingProfileAdded = FALSE;
  12101. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12102. {
  12103. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12104. json_object *tmpChargingProfile;
  12105. tmpChargingProfile = json_tokener_parse(dataLine);
  12106. if(!is_error(SetChargingProfile))
  12107. {
  12108. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12109. {
  12110. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12111. {
  12112. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12113. }
  12114. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12115. {
  12116. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12117. }
  12118. }
  12119. }
  12120. json_object_put(tmpChargingProfile);
  12121. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12122. {
  12123. if(ChargingProfileAdded == FALSE)
  12124. {
  12125. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12126. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12127. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12128. ChargingProfileAdded = TRUE;
  12129. }
  12130. }
  12131. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12132. {
  12133. if(ChargingProfileAdded == FALSE)
  12134. {
  12135. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12136. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12137. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12138. ChargingProfileAdded = TRUE;
  12139. }
  12140. }
  12141. else
  12142. {
  12143. fprintf(outfile,"%s\n",dataLine);
  12144. if(ChargingProfileAdded == FALSE)
  12145. {
  12146. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12147. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12148. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12149. ChargingProfileAdded = TRUE;
  12150. }
  12151. }
  12152. } // end of while loop
  12153. fclose(infile);
  12154. fclose(outfile);
  12155. sprintf(rmFileCmd,"rm -f %s",filename);
  12156. system(rmFileCmd);
  12157. rename(tempfile, filename);
  12158. }
  12159. }
  12160. sleep(1);
  12161. result = TRUE;
  12162. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12163. }
  12164. end:
  12165. json_object_put(SetChargingProfile);
  12166. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12167. {
  12168. if(SetProfileReq.ConnectorId == 0)
  12169. {
  12170. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12171. {
  12172. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12173. }
  12174. }
  12175. else
  12176. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12177. }
  12178. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12179. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12180. return result;
  12181. }
  12182. int handleTriggerMessageRequest(char *uuid, char *payload)
  12183. {
  12184. mtrace();
  12185. int result = FAIL;
  12186. int connectorIdIsNULL = FALSE;
  12187. int connectorIdInt =0;
  12188. char sstr[40]={0},sstrtemp[100]={ 0 };
  12189. char requestedMessagestr[40]={0};
  12190. char comfirmstr[20]={0};
  12191. int c = 0;
  12192. char *loc;
  12193. DEBUG_INFO("handleTriggerMessageRequest\n");
  12194. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12195. strcpy(sstrtemp, stringtrimspace(payload));
  12196. c = 0;
  12197. loc = strstr(sstrtemp, "requestedMessage");
  12198. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12199. {
  12200. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12201. c++;
  12202. }
  12203. sstr[c] = '\0';
  12204. strcpy(requestedMessagestr, sstr);
  12205. c = 0;
  12206. loc = strstr(sstrtemp, "connectorId");
  12207. if(loc == NULL)
  12208. {
  12209. connectorIdIsNULL = TRUE;
  12210. }
  12211. else
  12212. {
  12213. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12214. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12215. {
  12216. sstr[c] = loc[strlen("connectorId")+2+c];
  12217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12218. c++;
  12219. }
  12220. sstr[c] = '\0';
  12221. connectorIdInt = atoi(sstr);
  12222. }
  12223. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12224. {
  12225. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12226. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12227. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12228. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12229. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12230. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12231. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12232. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12233. {
  12234. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12235. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12236. return TRUE;
  12237. }
  12238. else
  12239. {
  12240. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12241. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12242. }
  12243. }
  12244. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12245. {
  12246. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12247. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12248. return TRUE;
  12249. }
  12250. //==========================
  12251. // Trigger message
  12252. //==========================
  12253. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12254. {
  12255. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12256. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12257. {
  12258. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12259. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12260. }
  12261. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12262. }
  12263. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12264. {
  12265. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12266. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12267. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12268. }
  12269. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12270. {
  12271. //sendBootNotificationRequest();
  12272. server_sign = FALSE;
  12273. }
  12274. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12275. {
  12276. refreshStartTimer(&clientTime.Heartbeat);
  12277. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12278. }
  12279. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12280. {
  12281. if(connectorIdIsNULL == FALSE)
  12282. {
  12283. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12284. {
  12285. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12286. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12287. }
  12288. }
  12289. else
  12290. {
  12291. for(int idx=0;idx< gunTotalNumber;idx++)
  12292. {
  12293. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12294. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12295. }
  12296. }
  12297. }
  12298. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12299. {
  12300. if(connectorIdIsNULL == FALSE)
  12301. {
  12302. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12303. {
  12304. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12305. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12306. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12307. }
  12308. }
  12309. else
  12310. {
  12311. for(int idx=0;idx< gunTotalNumber;idx++)
  12312. {
  12313. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12314. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12315. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12316. }
  12317. }
  12318. }
  12319. return result;
  12320. }
  12321. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12322. {
  12323. mtrace();
  12324. int result = FAIL;
  12325. int connectorIdInt =0;
  12326. char comfirmstr[20]={0};
  12327. int tempIndex = 0;
  12328. json_object *UnlockConnector;
  12329. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12330. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12331. UnlockConnector = json_tokener_parse(payload);
  12332. if(!is_error(UnlockConnector))
  12333. {
  12334. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12335. {
  12336. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12337. }
  12338. }
  12339. json_object_put(UnlockConnector);
  12340. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12341. if(gunTotalNumber == 0)
  12342. {
  12343. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12344. goto end;
  12345. }
  12346. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12347. {
  12348. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12349. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12350. goto end;
  12351. }
  12352. else
  12353. {
  12354. //check Transaction active
  12355. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12356. {
  12357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12358. {
  12359. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12360. }
  12361. else
  12362. {
  12363. tempIndex = connectorIdInt -1;
  12364. }
  12365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12366. {
  12367. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12368. {
  12369. //stop Transaction
  12370. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12371. }
  12372. }
  12373. }
  12374. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12375. {
  12376. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12377. {
  12378. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12379. }
  12380. else
  12381. {
  12382. tempIndex = connectorIdInt -1;
  12383. }
  12384. for (int index = 0; index < CCS_QUANTITY; index++)
  12385. {
  12386. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12387. {
  12388. //stop Transaction
  12389. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12390. }
  12391. }
  12392. }
  12393. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12394. {
  12395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12396. {
  12397. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12398. }
  12399. else
  12400. {
  12401. tempIndex = connectorIdInt -1;
  12402. }
  12403. for (int index = 0; index < GB_QUANTITY; index++)
  12404. {
  12405. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12406. {
  12407. //stop Transaction
  12408. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12409. }
  12410. }
  12411. }
  12412. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12413. {
  12414. tempIndex = connectorIdInt -1;
  12415. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12416. {
  12417. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12418. {
  12419. //stop Transaction
  12420. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12421. }
  12422. }
  12423. }
  12424. else
  12425. {
  12426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12427. {
  12428. tempIndex = 2;
  12429. }
  12430. else
  12431. {
  12432. tempIndex = connectorIdInt-1;
  12433. }
  12434. for (int index = 0; index < AC_QUANTITY; index++)
  12435. {
  12436. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12437. {
  12438. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12439. }
  12440. }
  12441. }
  12442. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12443. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12444. result = TRUE;
  12445. return result;
  12446. }
  12447. end:
  12448. //json_object_put(obj); --- remove temporally
  12449. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12450. return result;
  12451. }
  12452. static char UpdateFirmwarepayloadData[300]={0};
  12453. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12454. {
  12455. mtrace();
  12456. int result = FAIL;
  12457. pthread_t t;
  12458. sendUpdateFirmwareConfirmation(uuid);
  12459. memset(UpdateFirmwarepayloadData, 0, 300);
  12460. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12461. if(!interLock.isUpdateFirmwareGoing)
  12462. {
  12463. interLock.isUpdateFirmwareGoing = 1;
  12464. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12465. sleep(1);
  12466. }
  12467. else
  12468. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12469. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12470. return result;
  12471. }
  12472. void *UpdateFirmwareProcess(void *data)
  12473. {
  12474. pthread_detach(pthread_self());
  12475. mtrace();
  12476. int retriesInt =0, retryIntervalInt=0;
  12477. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12478. int port=0;
  12479. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12480. int isSuccess = 0;
  12481. char ftpbuf[512];
  12482. char temp[100];
  12483. char * pch;
  12484. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12485. json_object *UpdateFirmware;
  12486. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12487. if(!is_error(UpdateFirmware))
  12488. {
  12489. // Required data
  12490. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12491. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12492. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12493. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12494. // Optional data
  12495. if(json_object_object_get(UpdateFirmware, "retries"))
  12496. {
  12497. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12498. }
  12499. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12500. {
  12501. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12502. }
  12503. }
  12504. json_object_put(UpdateFirmware);
  12505. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12506. memset(path, 0, ARRAY_SIZE(path));
  12507. // Wait retrieveData
  12508. if(strlen(retrieveDatestr) > 10)
  12509. {
  12510. do
  12511. {
  12512. sleep(1);
  12513. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12514. }
  12515. // Ready to download
  12516. system("rm -f /mnt/*");
  12517. if(strncmp(locationstr,"http", 4) == 0)
  12518. {
  12519. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12520. sprintf(ftppath,"/%s", path);
  12521. DEBUG_INFO("locationstr: %s\n", locationstr);
  12522. DEBUG_INFO("protocol: %s\n",protocol);
  12523. DEBUG_INFO("host: %s\n",host);
  12524. DEBUG_INFO("path: %s\n",path);
  12525. DEBUG_INFO("ftppath: %s\n",ftppath);
  12526. int ftppathlen=strlen(ftppath);
  12527. int i=1;
  12528. char filenametemp[50];
  12529. while(i < ftppathlen)
  12530. {
  12531. int len=ftppathlen-i;
  12532. if(ftppath[len]== 47) // '/' ascll code: 47
  12533. {
  12534. DEBUG_INFO("compare '/' all right\n");
  12535. break;
  12536. }
  12537. i=i+1;
  12538. }
  12539. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12540. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12541. filenametemp[i+1] = 0;
  12542. do
  12543. {
  12544. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12545. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12546. sleep(1);
  12547. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12548. if(!isSuccess)
  12549. {
  12550. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12551. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12552. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12553. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12554. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12555. }
  12556. else
  12557. {
  12558. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12559. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12560. }
  12561. retriesInt--;
  12562. }while((isSuccess == 0)&&(retriesInt >= 0));
  12563. }
  12564. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12565. {
  12566. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12567. memset(temp, 0, ARRAY_SIZE(temp));
  12568. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12569. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12570. int ftppathlen=strlen(ftpbuf);
  12571. int i=1;
  12572. char filenametemp[50];
  12573. while(i < ftppathlen)
  12574. {
  12575. int len=ftppathlen-i;
  12576. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12577. {
  12578. DEBUG_INFO(" compare '/' all right\n");
  12579. break;
  12580. }
  12581. i=i+1;
  12582. }
  12583. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12584. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12585. filenametemp[i+1] = 0;
  12586. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12587. pch=strchr(temp,'@');
  12588. if(pch==NULL)
  12589. {
  12590. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12591. protocol, host, &port, path);
  12592. strcpy(user,"anonymous");
  12593. strcpy(password,"");
  12594. }
  12595. else
  12596. {
  12597. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12598. protocol, user, password, host, &port, path);
  12599. }
  12600. sscanf(host,"%[^/]%s",host1, path1);
  12601. sprintf(ftppath,"%s", path1);
  12602. //DEBUG_INFO("protocol =%s\n",protocol);
  12603. //DEBUG_INFO("user =%s\n",user);
  12604. //DEBUG_INFO("password =%s\n",password);
  12605. //DEBUG_INFO("host1 =%s\n",host1);
  12606. //DEBUG_INFO("port =%d\n",port);
  12607. //DEBUG_INFO("path1 =%s\n",path1);
  12608. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12609. //ftpFile(host, user, password, port, ftppath, fname);
  12610. //download firmware pthred
  12611. if(port == 0)
  12612. {
  12613. port = 21;
  12614. }
  12615. do
  12616. {
  12617. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12618. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12619. sleep(1);
  12620. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12621. if(!isSuccess)
  12622. {
  12623. //BulldogUtil.sleepMs(interval*1000);
  12624. DEBUG_INFO("Update firmware request and download file fail.\n");
  12625. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12626. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12627. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12628. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12629. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12630. }
  12631. else
  12632. {
  12633. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12634. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12635. }
  12636. retriesInt--;
  12637. }while((!isSuccess)&&(retriesInt >= 0));
  12638. }
  12639. else
  12640. {
  12641. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12642. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12643. sleep(1);
  12644. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12645. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12646. }
  12647. // OCPPPH only, must announce CSU upgrade firmware
  12648. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12649. interLock.isUpdateFirmwareGoing = 0;
  12650. pthread_exit(NULL);
  12651. }
  12652. int handleCertificateSignedRequest(char *uuid, char *payload)
  12653. {
  12654. mtrace();
  12655. int result = PASS;
  12656. json_object *CertificateSigned;
  12657. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12658. CertificateSigned = json_tokener_parse(payload);
  12659. if(!is_error(CertificateSigned))
  12660. {
  12661. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12662. }
  12663. json_object_put(CertificateSigned);
  12664. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12665. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12666. fclose(fp);
  12667. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12668. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12669. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12670. sendCertificateSignedConfirmation(uuid);
  12671. return result;
  12672. }
  12673. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12674. {
  12675. mtrace();
  12676. int result = PASS;
  12677. json_object *DeleteCertificate;
  12678. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12679. DeleteCertificate = json_tokener_parse(payload);
  12680. if(!is_error(DeleteCertificate))
  12681. {
  12682. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12683. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12684. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12685. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12686. }
  12687. json_object_put(DeleteCertificate);
  12688. /*
  12689. * TODO: Delete certificateSigned process
  12690. */
  12691. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12692. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12693. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12694. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12695. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12696. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12697. sendDeleteCertificateConfirmation(uuid);
  12698. return result;
  12699. }
  12700. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12701. {
  12702. mtrace();
  12703. int result = PASS;
  12704. json_object *ExtendedTriggerMessage;
  12705. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12706. ExtendedTriggerMessage = json_tokener_parse(payload);
  12707. if(!is_error(ExtendedTriggerMessage))
  12708. {
  12709. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12710. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12711. {
  12712. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12713. }
  12714. else
  12715. {
  12716. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12717. }
  12718. }
  12719. json_object_put(ExtendedTriggerMessage);
  12720. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12721. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12722. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12723. {
  12724. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12725. }
  12726. else
  12727. {
  12728. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12729. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12730. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12731. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12732. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12733. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12734. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12735. {
  12736. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12737. }
  12738. else
  12739. {
  12740. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12741. }
  12742. }
  12743. sendExtendedTriggerMessageConfirmation(uuid);
  12744. //==========================
  12745. // Trigger message
  12746. //==========================
  12747. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12748. {
  12749. //sendBootNotificationRequest();
  12750. server_sign = FALSE;
  12751. }
  12752. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12753. {
  12754. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12755. }
  12756. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12757. {
  12758. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12759. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12760. {
  12761. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12762. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12763. }
  12764. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12765. }
  12766. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12767. {
  12768. refreshStartTimer(&clientTime.Heartbeat);
  12769. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12770. }
  12771. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12772. {
  12773. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12774. {
  12775. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12776. }
  12777. else
  12778. {
  12779. for(int idx=0;idx< gunTotalNumber;idx++)
  12780. {
  12781. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12782. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12783. }
  12784. }
  12785. }
  12786. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12787. {
  12788. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12789. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12790. {
  12791. 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\" &");
  12792. }
  12793. }
  12794. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12795. {
  12796. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12797. {
  12798. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12799. }
  12800. else
  12801. {
  12802. for(int idx=0;idx< gunTotalNumber;idx++)
  12803. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12804. }
  12805. }
  12806. return result;
  12807. }
  12808. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12809. {
  12810. mtrace();
  12811. int result = PASS;
  12812. json_object *GetInstalledCertificateIds;
  12813. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12814. GetInstalledCertificateIds = json_tokener_parse(payload);
  12815. if(!is_error(GetInstalledCertificateIds))
  12816. {
  12817. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12818. }
  12819. json_object_put(GetInstalledCertificateIds);
  12820. /*
  12821. * TODO: Return installed certificate process
  12822. */
  12823. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12824. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12825. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12826. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12827. sendGetInstalledCertificateIdsConfirmation(uuid);
  12828. return result;
  12829. }
  12830. int handleGetLogRequest(char *uuid, char *payload)
  12831. {
  12832. mtrace();
  12833. int result = PASS;
  12834. json_object *GetLog;
  12835. DEBUG_INFO("handleGetLogRequest...\n");
  12836. GetLog = json_tokener_parse(payload);
  12837. if(!is_error(GetLog))
  12838. {
  12839. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12840. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12841. if(json_object_object_get(GetLog, "retries") != NULL)
  12842. {
  12843. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12844. }
  12845. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12846. {
  12847. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12848. }
  12849. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12850. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12851. {
  12852. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12853. }
  12854. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12855. {
  12856. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12857. }
  12858. }
  12859. json_object_put(GetLog);
  12860. /*
  12861. * TODO: Upload log process
  12862. */
  12863. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12864. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12865. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12866. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12867. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12868. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12869. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12870. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12871. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12872. sendGetLogConfirmation(uuid);
  12873. return result;
  12874. }
  12875. int handleInstallCertificateRequest(char *uuid, char *payload)
  12876. {
  12877. mtrace();
  12878. int result = PASS;
  12879. json_object *InstallCertificate;
  12880. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12881. InstallCertificate = json_tokener_parse(payload);
  12882. if(!is_error(InstallCertificate))
  12883. {
  12884. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12885. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12886. /*
  12887. * TODO: Install certificate process
  12888. */
  12889. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12890. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12891. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12892. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12893. sendInstallCertificateConfirmation(uuid);
  12894. }
  12895. json_object_put(InstallCertificate);
  12896. return result;
  12897. }
  12898. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12899. {
  12900. mtrace();
  12901. int result = PASS;
  12902. json_object *SignedUpdateFirmware;
  12903. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12904. SignedUpdateFirmware = json_tokener_parse(payload);
  12905. if(!is_error(SignedUpdateFirmware))
  12906. {
  12907. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12908. {
  12909. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12910. }
  12911. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12912. {
  12913. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12914. }
  12915. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12916. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12917. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12918. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12919. {
  12920. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12921. }
  12922. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12923. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12924. }
  12925. json_object_put(SignedUpdateFirmware);
  12926. /*
  12927. * TODO: Upgrade firmware process
  12928. */
  12929. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12930. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12931. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12932. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12933. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12934. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12935. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12936. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12937. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12938. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12939. sendInstallCertificateConfirmation(uuid);
  12940. return result;
  12941. }
  12942. int handleUnknownRequest(char *uuid, char *payload)
  12943. {
  12944. mtrace();
  12945. int result = PASS;
  12946. DEBUG_INFO("handleUnknownRequest...\n");
  12947. sendUnknownConfirmation(uuid);
  12948. result = PASS;
  12949. return result;
  12950. }
  12951. //==========================================
  12952. // Handle server response routine
  12953. //==========================================
  12954. void handleAuthorizeResponse(char *payload, int gun_index)
  12955. {
  12956. mtrace();
  12957. char expiryDatestr[30]={0};
  12958. char parentIdTagstr[20]={0};
  12959. char statusstr[20]={0};
  12960. int expiryDateISNULL=FALSE;
  12961. int parentIdTagISNULL=FALSE;
  12962. DEBUG_INFO("handleAuthorizeResponse...\n");
  12963. json_object *Authorize;
  12964. Authorize = json_tokener_parse(payload);
  12965. if(!is_error(Authorize))
  12966. {
  12967. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12968. {
  12969. // Required data
  12970. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12971. // Optional data
  12972. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12973. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12974. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12975. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12976. }
  12977. }
  12978. json_object_put(Authorize);
  12979. if(expiryDateISNULL == FALSE)
  12980. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12981. if(parentIdTagISNULL == FALSE)
  12982. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12983. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12984. //Update idTag information to authorization cache if supproted
  12985. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12986. {
  12987. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12988. }
  12989. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12990. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12991. authorizeRetryTimes = 0;
  12992. }
  12993. void handleBootNotificationResponse(char *payload, int gun_index)
  12994. {
  12995. mtrace();
  12996. char statusStr[12]={0};
  12997. char currentTimeStr[30]={0};
  12998. int intervalInt = 0;
  12999. DEBUG_INFO("handleBootNotificationResponse...\n");
  13000. json_object *BootNotification;
  13001. BootNotification = json_tokener_parse(payload);
  13002. if(!is_error(BootNotification))
  13003. {
  13004. // Required data
  13005. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13006. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13007. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13008. }
  13009. json_object_put(BootNotification);
  13010. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13011. BootNotificationInterval = intervalInt;
  13012. HeartBeatWaitTime = intervalInt;
  13013. //write back to ShmOCPP16DataPH->BootNotification
  13014. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13015. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13016. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13017. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13018. {
  13019. if((intervalInt == 0) || (intervalInt >= 10))
  13020. {
  13021. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13022. HeartBeatWaitTime = intervalInt;
  13023. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13024. }
  13025. server_sign = TRUE;
  13026. server_pending =FALSE;
  13027. }
  13028. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13029. {
  13030. server_pending = TRUE;
  13031. }
  13032. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13033. srand(time(NULL));
  13034. refreshStartTimer(&clientTime.Heartbeat);
  13035. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13036. SetOcppConnStatus(TRUE);
  13037. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13038. }
  13039. void handleDataTransferResponse(char *payload, int gun_index)
  13040. {
  13041. json_object *DataTransfer = json_tokener_parse(payload);
  13042. if(!is_error(DataTransfer))
  13043. {
  13044. // Required data
  13045. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13046. // Optional data
  13047. if(json_object_object_get(DataTransfer, "data") != NULL)
  13048. {
  13049. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13050. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13051. if(!is_error(Data))
  13052. {
  13053. if(json_object_object_get(Data, "msgId") != NULL)
  13054. {
  13055. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13056. {
  13057. 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")));
  13058. }
  13059. }
  13060. }
  13061. json_object_put(Data);
  13062. }
  13063. }
  13064. json_object_put(DataTransfer);
  13065. }
  13066. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13067. {
  13068. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13069. //struct json_object *obj;
  13070. // obj = json_tokener_parse(payload);
  13071. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13072. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13073. //No fields are defined.
  13074. }
  13075. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13076. {
  13077. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13078. //struct json_object *obj;
  13079. // obj = json_tokener_parse(payload);
  13080. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13081. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13082. //No fields are defined.
  13083. }
  13084. void handleHeartbeatResponse(char *payload, int gun_index)
  13085. {
  13086. mtrace();
  13087. DEBUG_INFO("handleHeartbeatResponse...\n");
  13088. json_object *Heartbeat;
  13089. Heartbeat = json_tokener_parse(payload);
  13090. if(!is_error(Heartbeat))
  13091. {
  13092. // Required data
  13093. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13094. }
  13095. json_object_put(Heartbeat);
  13096. if(FirstHeartBeat == 0)
  13097. {
  13098. FirstHeartBeat = 1;
  13099. DEBUG_INFO("FirstHeartBeat \n");
  13100. }
  13101. HeartBeatWithNOResponse = 0;
  13102. refreshStartTimer(&clientTime.Heartbeat);
  13103. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13104. }
  13105. void handleMeterValuesResponse(char *payload, int gun_index)
  13106. {
  13107. mtrace();
  13108. DEBUG_INFO("handleMeterValuesResponse...\n");
  13109. isQueueSendable = 1;
  13110. }
  13111. void handleStartTransactionResponse(char *payload, int gun_index)
  13112. {
  13113. mtrace();
  13114. //int transactionIdInt = 0;
  13115. FILE *outfile;
  13116. char data[100]={0};
  13117. DEBUG_INFO("handleStartTransactionResponse...\n");
  13118. json_object *StartTransaction;
  13119. StartTransaction = json_tokener_parse(payload);
  13120. if(!is_error(StartTransaction))
  13121. {
  13122. // Required data
  13123. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13124. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13125. // Optional data
  13126. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13127. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13128. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13129. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13130. }
  13131. json_object_put(StartTransaction);
  13132. isQueueSendable = 1;
  13133. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13134. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13135. //-----------Start : write to the Queue TransactionId file -----------------//
  13136. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13137. {}
  13138. else
  13139. {
  13140. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13141. if(log == NULL)
  13142. {
  13143. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13144. return ;
  13145. }
  13146. else
  13147. {
  13148. fclose(log);
  13149. }
  13150. }
  13151. // open file for writing
  13152. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13153. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13154. {
  13155. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13156. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13157. fputs(data, outfile);
  13158. fclose (outfile);
  13159. }
  13160. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13161. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13162. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13163. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13164. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13165. }
  13166. void handleStatusNotificationResponse(char *payload, int gun_index)
  13167. {
  13168. mtrace();
  13169. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13170. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13172. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13173. }
  13174. void handleStopTransactionnResponse(char *payload, int gun_index)
  13175. {
  13176. mtrace();
  13177. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13178. json_object *StopTransaction;
  13179. StopTransaction = json_tokener_parse(payload);
  13180. if(!is_error(StopTransaction))
  13181. {
  13182. // Optional data
  13183. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13184. {
  13185. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13186. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13187. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13188. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13189. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13190. }
  13191. }
  13192. json_object_put(StopTransaction);
  13193. isQueueSendable = 1;
  13194. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13195. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13196. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13197. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13198. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13199. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13200. }
  13201. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13202. {
  13203. mtrace();
  13204. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13205. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13206. }
  13207. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13208. {
  13209. mtrace();
  13210. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13211. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13212. }
  13213. void handleSignCertificateResponse(char *payload, int gun_index)
  13214. {
  13215. mtrace();
  13216. DEBUG_INFO("handleSignCertificateResponse...\n");
  13217. json_object *SignCertificate;
  13218. SignCertificate = json_tokener_parse(payload);
  13219. if(!is_error(SignCertificate))
  13220. {
  13221. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13222. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13223. }
  13224. json_object_put(SignCertificate);
  13225. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13226. }
  13227. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13228. {
  13229. mtrace();
  13230. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13231. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13232. }
  13233. //==========================================
  13234. // Handle Error routine
  13235. //==========================================
  13236. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13237. {
  13238. mtrace();
  13239. #ifdef SystemLogMessage
  13240. DEBUG_INFO("errorCode: %s\n", errorCode);
  13241. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13242. DEBUG_INFO("errorDetails: %s\n", payload);
  13243. #endif
  13244. }
  13245. //===============================================
  13246. // Common routine
  13247. //===============================================
  13248. int initialConfigurationTable(void)
  13249. {
  13250. //clock_t start_t, end_t, total_t;
  13251. FILE *fp;
  13252. FILE *outfile;
  13253. char str[512]={0};
  13254. char sstr[256]={0};
  13255. int c = 0;
  13256. char *loc;
  13257. int confVersion = 13;
  13258. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13259. //start_t = clock();
  13260. //printf("Starting of the program, start_t = %ld\n", start_t);
  13261. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13262. // Check configuration file size is correct
  13263. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13264. {
  13265. struct stat st;
  13266. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13267. if(st.st_size < 3100)
  13268. {
  13269. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13270. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13271. }
  13272. }
  13273. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13274. {
  13275. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13276. if(outfile == NULL)
  13277. {
  13278. DEBUG_INFO("Error opening file\n");
  13279. return FALSE;
  13280. }
  13281. /*Core Profile*/
  13282. //AllowOfflineTxForUnknownId
  13283. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13287. //AuthorizationCacheEnabled
  13288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13292. //AuthorizeRemoteTxRequests
  13293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13297. //BlinkRepeat
  13298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13302. //ClockAlignedDataInterval
  13303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13307. //ConnectionTimeOut
  13308. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13312. //GetConfigurationMaxKeys
  13313. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13315. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13317. // HeartbeatInterval
  13318. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13322. // LightIntensity
  13323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13327. // LocalAuthorizeOffline
  13328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13329. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13332. // LocalPreAuthorize
  13333. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13337. // MaxEnergyOnInvalidId
  13338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13342. // MeterValuesAlignedData
  13343. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13344. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13346. 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" );
  13347. else
  13348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13350. // MeterValuesAlignedDataMaxLength
  13351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13355. else
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13358. // MeterValuesSampledData
  13359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13362. 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" );
  13363. else
  13364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13366. // MeterValuesSampledDataMaxLength
  13367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13371. else
  13372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13374. // MeterValueSampleInterval
  13375. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13379. // MinimumStatusDuration
  13380. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13383. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13385. // NumberOfConnectors
  13386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13388. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13389. {
  13390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13391. }
  13392. else
  13393. {
  13394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13395. }
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13397. // ResetRetries
  13398. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13402. // ConnectorPhaseRotation
  13403. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13407. // ConnectorPhaseRotationMaxLength
  13408. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13410. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13412. // StopTransactionOnEVSideDisconnect
  13413. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13414. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13415. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13417. // StopTransactionOnInvalidId
  13418. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13420. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13422. // StopTxnAlignedData
  13423. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13427. // StopTxnAlignedDataMaxLength
  13428. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13429. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13432. // StopTxnSampledData
  13433. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13437. else
  13438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13440. // StopTxnSampledDataMaxLength
  13441. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13444. {
  13445. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13446. }
  13447. else
  13448. {
  13449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13450. }
  13451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13452. // SupportedFeatureProfiles
  13453. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13455. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13457. // SupportedFeatureProfilesMaxLength
  13458. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13459. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13460. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13462. // TransactionMessageAttempts
  13463. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13464. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13465. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13466. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13468. // TransactionMessageRetryInterval
  13469. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13470. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13472. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13474. // UnlockConnectorOnEVSideDisconnect
  13475. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13479. // WebSocketPingInterval
  13480. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13481. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13484. // QueueOffLineMeterValues
  13485. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13486. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13489. // AuthorizationKey
  13490. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13491. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13492. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13494. // SecurityProfile
  13495. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13496. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13497. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13499. // DefaultPrice
  13500. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13501. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13504. // CustomDisplayCostAndPrice
  13505. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13506. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13507. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13509. // CustomIdleFeeAfterStop
  13510. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13514. // SystemUptimeSec
  13515. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13516. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13517. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13519. // FreeVend
  13520. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13521. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13524. // FreeVendIdtag
  13525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13526. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13529. // OcppServer
  13530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13531. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13532. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13534. // MaintainServer
  13535. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13536. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13537. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13539. // StatusNotificationPeriodically
  13540. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13541. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13544. // StatusNotificationInterval
  13545. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13546. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13549. // Configuration Version
  13550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13551. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13554. //* Local Auth List Management Profile*/
  13555. #if 0
  13556. //For OCTT Test Case
  13557. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13560. #endif
  13561. #if 1
  13562. //LocalAuthListEnabled
  13563. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13567. #endif
  13568. //LocalAuthListMaxLength
  13569. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13573. //SendLocalListMaxLength
  13574. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13578. //ReserveConnectorZeroSupported
  13579. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13583. //* Smart Charging Profile */
  13584. //ChargeProfileMaxStackLevel
  13585. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13586. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13589. // ChargingScheduleAllowedChargingRateUnit
  13590. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13594. // ChargingScheduleMaxPeriods
  13595. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13599. // ConnectorSwitch3to1PhaseSupported
  13600. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13604. // MaxChargingProfilesInstalled
  13605. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13609. fclose(outfile);
  13610. }
  13611. else
  13612. {
  13613. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13614. char keystr[60]={0};
  13615. char readonlystr[10]={0};
  13616. char valuestr[256]={0};
  13617. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13618. if(fp == NULL) {
  13619. DEBUG_INFO("Error opening file");
  13620. return FALSE;
  13621. }
  13622. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13623. {
  13624. //DEBUG_INFO("Get Configuration \n");
  13625. if(strlen(str) > 0)
  13626. {
  13627. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13628. //*************************key*********************************/
  13629. if(strstr(str, "key") != NULL)
  13630. {
  13631. loc = strstr(str, "key");
  13632. c = 0;
  13633. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13634. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13635. {
  13636. sstr[c] = loc[strlen("key")+3+c];
  13637. c++;
  13638. }
  13639. sstr[c] = '\0';
  13640. strcpy(keystr,sstr);
  13641. }
  13642. //*************************readonly*********************************/
  13643. if(strstr(str, "readonly") != NULL)
  13644. {
  13645. loc = strstr(str, "readonly");
  13646. c = 0;
  13647. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13648. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13649. {
  13650. sstr[c] = loc[strlen("readonly")+2+c];
  13651. c++;
  13652. }
  13653. sstr[c] = '\0';
  13654. strcpy(readonlystr,sstr);
  13655. }
  13656. //*************************value*********************************/
  13657. if(strstr(str, "value") != NULL)
  13658. {
  13659. loc = strstr(str, "value");
  13660. c = 0;
  13661. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13662. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13663. {
  13664. sstr[c] = loc[strlen("value")+3+c];
  13665. c++;
  13666. }
  13667. sstr[c] = '\0';
  13668. strcpy(valuestr,sstr);
  13669. }
  13670. // DEBUG_INFO("keystr=%s\n",keystr);
  13671. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13672. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13673. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13674. {
  13675. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13676. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13677. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13678. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13679. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13680. }
  13681. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13682. {
  13683. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13686. }
  13687. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13688. {
  13689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13691. }
  13692. if(strcmp(keystr, "BlinkRepeat") == 0)
  13693. {
  13694. //Charger.BlinkRepeat = Integer.parseInt(value);
  13695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13697. }
  13698. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13699. {
  13700. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13702. }
  13703. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13704. {
  13705. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13707. }
  13708. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13709. {
  13710. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13711. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13712. }
  13713. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13714. {
  13715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13717. HeartBeatWaitTime = atoi(valuestr);
  13718. }
  13719. if(strcmp(keystr, "LightIntensity") == 0)
  13720. {
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13722. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13723. }
  13724. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13725. {
  13726. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13727. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13728. }
  13729. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13730. {
  13731. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13732. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13733. }
  13734. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13735. {
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13738. }
  13739. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13740. {
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13743. }
  13744. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13745. {
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13748. }
  13749. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13750. {
  13751. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13753. }
  13754. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13755. {
  13756. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13758. }
  13759. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13760. {
  13761. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13763. }
  13764. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13765. {
  13766. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13768. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13769. }
  13770. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13771. {
  13772. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13774. }
  13775. if(strcmp(keystr, "ResetRetries") == 0)
  13776. {
  13777. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13778. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13779. }
  13780. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13781. {
  13782. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13784. }
  13785. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13786. {
  13787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13789. }
  13790. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13791. {
  13792. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13794. }
  13795. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13796. {
  13797. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13798. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13799. }
  13800. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13801. {
  13802. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13804. }
  13805. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13806. {
  13807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13809. }
  13810. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13811. {
  13812. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13813. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13814. }
  13815. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13816. {
  13817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13818. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13819. }
  13820. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13821. {
  13822. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13823. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13824. }
  13825. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13826. {
  13827. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13829. }
  13830. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13831. {
  13832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13833. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13834. TransactionMessageAttemptsValue = atoi(valuestr);
  13835. }
  13836. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13837. {
  13838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13839. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13840. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13841. }
  13842. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13843. {
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13846. }
  13847. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13848. {
  13849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13851. }
  13852. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13853. {
  13854. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13855. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13856. }
  13857. if(strcmp(keystr, "AuthorizationKey") == 0)
  13858. {
  13859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13860. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13862. }
  13863. if(strcmp(keystr, "SecurityProfile") == 0)
  13864. {
  13865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13866. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13867. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13868. }
  13869. if(strcmp(keystr, "DefaultPrice") == 0)
  13870. {
  13871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13872. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13873. }
  13874. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13875. {
  13876. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13877. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13878. }
  13879. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13880. {
  13881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13882. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13883. }
  13884. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13885. {
  13886. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13887. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13888. }
  13889. if(strcmp(keystr, "FreeVend") == 0)
  13890. {
  13891. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13892. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13893. }
  13894. if(strcmp(keystr, "FreeVendIdtag") == 0)
  13895. {
  13896. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13897. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  13898. }
  13899. if(strcmp(keystr, "OcppServer") == 0)
  13900. {
  13901. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13902. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13903. }
  13904. if(strcmp(keystr, "MaintainServer") == 0)
  13905. {
  13906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13907. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13908. }
  13909. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13910. {
  13911. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13912. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13913. }
  13914. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13915. {
  13916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13918. }
  13919. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13920. {
  13921. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13922. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13923. }
  13924. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13925. {
  13926. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13928. }
  13929. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13930. {
  13931. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13932. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13933. }
  13934. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13935. {
  13936. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13938. }
  13939. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13940. {
  13941. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13942. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13943. }
  13944. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13945. {
  13946. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13947. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13948. }
  13949. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13950. {
  13951. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13953. }
  13954. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13955. {
  13956. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13957. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13958. }
  13959. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13960. {
  13961. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13963. }
  13964. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13965. {
  13966. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13967. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13968. }
  13969. }
  13970. }
  13971. fclose(fp);
  13972. }
  13973. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13974. {
  13975. return PASS;
  13976. }
  13977. else
  13978. {
  13979. return FAIL;
  13980. }
  13981. }
  13982. void StoreConfigurationTable(void)
  13983. {
  13984. FILE *outfile;
  13985. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13986. if(outfile == NULL)
  13987. {
  13988. DEBUG_INFO("Error opening file");
  13989. return ;
  13990. }
  13991. /*Core Profile*/
  13992. //AllowOfflineTxForUnknownId
  13993. /*
  13994. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13995. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13998. */
  13999. //DEBUG_INFO("data=%s\n",data);
  14000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14001. //AuthorizationCacheEnabled
  14002. /*
  14003. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14006. */
  14007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14008. //AuthorizeRemoteTxRequests
  14009. /*
  14010. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14013. */
  14014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14015. //BlinkRepeat
  14016. /*
  14017. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14020. */
  14021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14022. //ClockAlignedDataInterval
  14023. /*
  14024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14027. */
  14028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14029. //ConnectionTimeOut
  14030. /*
  14031. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14032. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14034. */
  14035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14036. //GetConfigurationMaxKeys
  14037. /*
  14038. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14041. */
  14042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14043. // HeartbeatInterval
  14044. /*
  14045. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14048. */
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14050. // LightIntensity
  14051. /*
  14052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14055. */
  14056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14057. // LocalAuthorizeOffline
  14058. /*
  14059. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14060. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14062. */
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14064. // LocalPreAuthorize
  14065. /*
  14066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14069. */
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14071. // MaxEnergyOnInvalidId
  14072. /*
  14073. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14074. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14075. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14076. */
  14077. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14079. // MeterValuesAlignedData
  14080. /*
  14081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14084. */
  14085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14086. // MeterValuesAlignedDataMaxLength
  14087. /*
  14088. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14091. */
  14092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14093. // MeterValuesSampledData
  14094. /*
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14098. */
  14099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14100. // MeterValuesSampledDataMaxLength
  14101. /*
  14102. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14105. */
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14107. // MeterValueSampleInterval
  14108. /*
  14109. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14112. */
  14113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14114. // MinimumStatusDuration
  14115. /*
  14116. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14119. */
  14120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14121. // NumberOfConnectors
  14122. /*
  14123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14126. {
  14127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14128. }
  14129. else
  14130. {
  14131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14132. }
  14133. */
  14134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14135. // ResetRetries
  14136. /*
  14137. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14140. */
  14141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14142. // ConnectorPhaseRotation
  14143. /*
  14144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14147. */
  14148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14149. // ConnectorPhaseRotationMaxLength
  14150. /*
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14154. */
  14155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14156. // StopTransactionOnEVSideDisconnect
  14157. /*
  14158. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14161. */
  14162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14163. // StopTransactionOnInvalidId
  14164. /*
  14165. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14168. */
  14169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14170. // StopTxnAlignedData
  14171. /*
  14172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14175. */
  14176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14177. // StopTxnAlignedDataMaxLength
  14178. /*
  14179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14182. */
  14183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14184. // StopTxnSampledData
  14185. /*
  14186. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14189. */
  14190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14191. // StopTxnSampledDataMaxLength
  14192. /*
  14193. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14196. */
  14197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14198. // SupportedFeatureProfiles
  14199. /*
  14200. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14203. */
  14204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14205. // SupportedFeatureProfilesMaxLength
  14206. /*
  14207. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14210. */
  14211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14212. // TransactionMessageAttempts
  14213. /*
  14214. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14217. */
  14218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14219. // TransactionMessageRetryInterval
  14220. /*
  14221. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14224. */
  14225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14226. // UnlockConnectorOnEVSideDisconnect
  14227. /*
  14228. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14229. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14231. */
  14232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14233. // WebSocketPingInterval
  14234. /*
  14235. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14237. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14238. */
  14239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14240. // QueueOffLineMeterValues
  14241. /*
  14242. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14245. */
  14246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14247. // AuthorizationKey
  14248. /*
  14249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14252. */
  14253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14254. // SecurityProfile
  14255. /*
  14256. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14257. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14258. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14259. */
  14260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14261. // DefaultPrice
  14262. /*
  14263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14266. */
  14267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14268. // CustomDisplayCostAndPrice
  14269. /*
  14270. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14272. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14273. */
  14274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14275. // CustomIdleFeeAfterStop
  14276. /*
  14277. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14280. */
  14281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14282. // SystemUptimeSec
  14283. /*
  14284. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14287. */
  14288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14289. // FreeVend
  14290. /*
  14291. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14294. */
  14295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14296. // FreeVendIdtag
  14297. /*
  14298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14301. */
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14303. // OcppServer
  14304. /*
  14305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14308. */
  14309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14310. // MaintainServer
  14311. /*
  14312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14315. */
  14316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14317. // StatusNotificationPeriodically
  14318. /*
  14319. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14322. */
  14323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14324. // StatusNotificationInterval
  14325. /*
  14326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14329. */
  14330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14331. // ConfigurationVersion
  14332. /*
  14333. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14336. */
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14338. //* Local Auth List Management Profile*/
  14339. //LocalAuthListEnabled
  14340. /*
  14341. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14344. */
  14345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14346. //LocalAuthListMaxLength
  14347. /*
  14348. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14351. */
  14352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14353. //SendLocalListMaxLength
  14354. /*
  14355. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14358. */
  14359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14360. //ReserveConnectorZeroSupported
  14361. /*
  14362. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14365. */
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14367. //* Smart Charging Profile */
  14368. //ChargeProfileMaxStackLevel
  14369. /*
  14370. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14373. */
  14374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14375. // ChargingScheduleAllowedChargingRateUnit
  14376. /*
  14377. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14380. */
  14381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14382. // ChargingScheduleMaxPeriods
  14383. /*
  14384. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14387. */
  14388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14389. // ConnectorSwitch3to1PhaseSupported
  14390. /*
  14391. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14394. */
  14395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14396. // MaxChargingProfilesInstalled
  14397. /*
  14398. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14401. */
  14402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14403. fclose(outfile);
  14404. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14405. }
  14406. void getKeyValue(char *keyReq)
  14407. {
  14408. int isEmpty = FALSE;
  14409. int isKnowKey = FALSE;
  14410. DEBUG_INFO("keyReq = %s\n", keyReq);
  14411. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14412. isEmpty = TRUE;
  14413. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14414. {
  14415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14418. {
  14419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14420. }
  14421. else
  14422. {
  14423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14424. }
  14425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14426. isKnowKey = TRUE;
  14427. }
  14428. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14429. {
  14430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14433. {
  14434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14435. }
  14436. else
  14437. {
  14438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14439. }
  14440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14441. isKnowKey = TRUE;
  14442. }
  14443. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14444. {
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14447. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14448. {
  14449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14450. }
  14451. else
  14452. {
  14453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14454. }
  14455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14456. isKnowKey = TRUE;
  14457. }
  14458. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14459. {
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14462. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14463. {
  14464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14465. }
  14466. else
  14467. {
  14468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14469. }
  14470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14471. isKnowKey = TRUE;
  14472. }
  14473. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14474. {
  14475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14477. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14478. {
  14479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14480. }
  14481. else
  14482. {
  14483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14484. }
  14485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14486. isKnowKey = TRUE;
  14487. }
  14488. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14489. {
  14490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14492. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14493. {
  14494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14495. }
  14496. else
  14497. {
  14498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14499. }
  14500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14501. isKnowKey = TRUE;
  14502. }
  14503. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14504. {
  14505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14507. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14508. {
  14509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14510. }
  14511. else
  14512. {
  14513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14514. }
  14515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14516. isKnowKey = TRUE;
  14517. }
  14518. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14519. {
  14520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14522. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14523. {
  14524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14525. }
  14526. else
  14527. {
  14528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14529. }
  14530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14531. isKnowKey = TRUE;
  14532. }
  14533. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14534. {
  14535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14537. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14538. {
  14539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14540. }
  14541. else
  14542. {
  14543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14544. }
  14545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14546. isKnowKey = TRUE;
  14547. }
  14548. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14549. {
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14552. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14553. {
  14554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14555. }
  14556. else
  14557. {
  14558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14559. }
  14560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14561. isKnowKey = TRUE;
  14562. }
  14563. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14564. {
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14567. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14568. {
  14569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14570. }
  14571. else
  14572. {
  14573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14574. }
  14575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14576. isKnowKey = TRUE;
  14577. }
  14578. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14579. {
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14582. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14583. {
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14585. }
  14586. else
  14587. {
  14588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14589. }
  14590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14591. isKnowKey = TRUE;
  14592. }
  14593. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14594. {
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14597. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14598. {
  14599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14600. }
  14601. else
  14602. {
  14603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14604. }
  14605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14606. isKnowKey = TRUE;
  14607. }
  14608. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14609. {
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14612. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14613. {
  14614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14615. }
  14616. else
  14617. {
  14618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14619. }
  14620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14621. isKnowKey = TRUE;
  14622. }
  14623. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14624. {
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14627. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14628. {
  14629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14630. }
  14631. else
  14632. {
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14634. }
  14635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14636. isKnowKey = TRUE;
  14637. }
  14638. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14639. {
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14642. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14643. {
  14644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14645. }
  14646. else
  14647. {
  14648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14649. }
  14650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14651. isKnowKey = TRUE;
  14652. }
  14653. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14654. {
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14657. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14658. {
  14659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14660. }
  14661. else
  14662. {
  14663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14664. }
  14665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14666. isKnowKey = TRUE;
  14667. }
  14668. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14669. {
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14673. {
  14674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14675. }
  14676. else
  14677. {
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14679. }
  14680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14681. isKnowKey = TRUE;
  14682. }
  14683. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14684. {
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14687. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14688. {
  14689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14690. }
  14691. else
  14692. {
  14693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14694. }
  14695. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14697. isKnowKey = TRUE;
  14698. }
  14699. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14700. {
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14704. {
  14705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14706. }
  14707. else
  14708. {
  14709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14710. }
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14712. isKnowKey = TRUE;
  14713. }
  14714. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14715. {
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14718. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14719. {
  14720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14721. }
  14722. else
  14723. {
  14724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14725. }
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14727. isKnowKey = TRUE;
  14728. }
  14729. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14730. {
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14733. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14734. {
  14735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14736. }
  14737. else
  14738. {
  14739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14740. }
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14742. isKnowKey = TRUE;
  14743. }
  14744. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14745. {
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14748. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14749. {
  14750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14751. }
  14752. else
  14753. {
  14754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14755. }
  14756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14757. isKnowKey = TRUE;
  14758. }
  14759. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14760. {
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14764. {
  14765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14766. }
  14767. else
  14768. {
  14769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14770. }
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14772. isKnowKey = TRUE;
  14773. }
  14774. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14775. {
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14779. {
  14780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14781. }
  14782. else
  14783. {
  14784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14785. }
  14786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14787. isKnowKey = TRUE;
  14788. }
  14789. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14790. {
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14794. {
  14795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14796. }
  14797. else
  14798. {
  14799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14800. }
  14801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14802. isKnowKey = TRUE;
  14803. }
  14804. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14805. {
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14808. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14809. {
  14810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14811. }
  14812. else
  14813. {
  14814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14815. }
  14816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14817. isKnowKey = TRUE;
  14818. }
  14819. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14820. {
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14823. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14824. {
  14825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14826. }
  14827. else
  14828. {
  14829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14830. }
  14831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14832. isKnowKey = TRUE;
  14833. }
  14834. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14835. {
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14838. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14839. {
  14840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14841. }
  14842. else
  14843. {
  14844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14845. }
  14846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14847. isKnowKey = TRUE;
  14848. }
  14849. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14850. {
  14851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14853. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14854. {
  14855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14856. }
  14857. else
  14858. {
  14859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14860. }
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14862. isKnowKey = TRUE;
  14863. }
  14864. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14865. {
  14866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14869. {
  14870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14871. }
  14872. else
  14873. {
  14874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14875. }
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14877. isKnowKey = TRUE;
  14878. }
  14879. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14880. {
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14883. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14884. {
  14885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14886. }
  14887. else
  14888. {
  14889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14890. }
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14892. isKnowKey = TRUE;
  14893. }
  14894. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14895. {
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14898. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14899. {
  14900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14901. }
  14902. else
  14903. {
  14904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14905. }
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14907. isKnowKey = TRUE;
  14908. }
  14909. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14910. {
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14914. {
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14916. }
  14917. else
  14918. {
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14920. }
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14922. isKnowKey = TRUE;
  14923. }
  14924. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14925. {
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14928. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14929. {
  14930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14931. }
  14932. else
  14933. {
  14934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14935. }
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14937. isKnowKey = TRUE;
  14938. }
  14939. /*
  14940. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14941. {
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14944. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14945. {
  14946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14947. }
  14948. else
  14949. {
  14950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14951. }
  14952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14953. isKnowKey = TRUE;
  14954. }*/
  14955. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14956. {
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14959. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14960. {
  14961. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14962. }
  14963. else
  14964. {
  14965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14966. }
  14967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14968. isKnowKey = TRUE;
  14969. }
  14970. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14971. {
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14974. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14975. {
  14976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14977. }
  14978. else
  14979. {
  14980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14981. }
  14982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14983. isKnowKey = TRUE;
  14984. }
  14985. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14989. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14990. {
  14991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14992. }
  14993. else
  14994. {
  14995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14996. }
  14997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14998. isKnowKey = TRUE;
  14999. }
  15000. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15001. {
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15005. {
  15006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15007. }
  15008. else
  15009. {
  15010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15011. }
  15012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15013. isKnowKey = TRUE;
  15014. }
  15015. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15016. {
  15017. struct sysinfo s_info;
  15018. int error = sysinfo(&s_info);
  15019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15021. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15022. {
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15024. }
  15025. else
  15026. {
  15027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15028. }
  15029. if(error != 0)
  15030. {
  15031. DEBUG_WARN("System uptime get error: %d\n", error);
  15032. }
  15033. else
  15034. {
  15035. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15036. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15037. }
  15038. isKnowKey = TRUE;
  15039. }
  15040. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15041. {
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15044. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15045. {
  15046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15047. }
  15048. else
  15049. {
  15050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15051. }
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15053. isKnowKey = TRUE;
  15054. }
  15055. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15056. {
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15059. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15060. {
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15062. }
  15063. else
  15064. {
  15065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15066. }
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15068. isKnowKey = TRUE;
  15069. }
  15070. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15071. {
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15074. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15075. {
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15077. }
  15078. else
  15079. {
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15081. }
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15083. isKnowKey = TRUE;
  15084. }
  15085. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15086. {
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15089. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15090. {
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15092. }
  15093. else
  15094. {
  15095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15096. }
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15098. isKnowKey = TRUE;
  15099. }
  15100. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15101. {
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15104. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15105. {
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15107. }
  15108. else
  15109. {
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15111. }
  15112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15113. isKnowKey = TRUE;
  15114. }
  15115. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15116. {
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15119. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15120. {
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15122. }
  15123. else
  15124. {
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15126. }
  15127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15128. isKnowKey = TRUE;
  15129. }
  15130. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15131. {
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15135. {
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15137. }
  15138. else
  15139. {
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15141. }
  15142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15143. isKnowKey = TRUE;
  15144. }
  15145. #if 1
  15146. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15147. {
  15148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15150. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15151. {
  15152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15153. }
  15154. else
  15155. {
  15156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15157. }
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15159. isKnowKey = TRUE;
  15160. }
  15161. #endif
  15162. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15163. {
  15164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15166. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15167. {
  15168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15169. }
  15170. else
  15171. {
  15172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15173. }
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15175. isKnowKey = TRUE;
  15176. }
  15177. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15178. {
  15179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15181. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15182. {
  15183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15184. }
  15185. else
  15186. {
  15187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15188. }
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15190. isKnowKey = TRUE;
  15191. }
  15192. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15193. {
  15194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15196. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15197. {
  15198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15199. }
  15200. else
  15201. {
  15202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15203. }
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15205. isKnowKey = TRUE;
  15206. }
  15207. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15208. {
  15209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15211. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15212. {
  15213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15214. }
  15215. else
  15216. {
  15217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15218. }
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15220. isKnowKey = TRUE;
  15221. }
  15222. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15223. {
  15224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15226. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15227. {
  15228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15229. }
  15230. else
  15231. {
  15232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15233. }
  15234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15235. isKnowKey = TRUE;
  15236. }
  15237. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15238. {
  15239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15241. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15242. {
  15243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15244. }
  15245. else
  15246. {
  15247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15248. }
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15250. isKnowKey = TRUE;
  15251. }
  15252. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15253. {
  15254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15256. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15257. {
  15258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15259. }
  15260. else
  15261. {
  15262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15263. }
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15265. isKnowKey = TRUE;
  15266. }
  15267. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15268. {
  15269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15271. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15272. {
  15273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15274. }
  15275. else
  15276. {
  15277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15278. }
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15280. isKnowKey = TRUE;
  15281. }
  15282. //=========================================================
  15283. if(!isEmpty && !isKnowKey)
  15284. {
  15285. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15286. strcpy(unknownkey[UnknownKeynum], keyReq);
  15287. UnknownKeynum = UnknownKeynum + 1;
  15288. }
  15289. }
  15290. void processUnkownKey(void)
  15291. {
  15292. DEBUG_INFO("processUnkownKey...\n");
  15293. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15294. for(int index=0; index < UnknownKeynum; index++)
  15295. {
  15296. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15297. {
  15298. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15299. }
  15300. }
  15301. }
  15302. int setKeyValue(char *key, char *value)
  15303. {
  15304. int isSuccess = NotSupported;
  15305. int check_ascii=0;
  15306. char str[501]={0};
  15307. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15308. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15309. {
  15310. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15311. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15312. {
  15313. strcpy(str, (const char*)value);
  15314. for(int i = 0; str[i]; i++){
  15315. str[i] = tolower(str[i]);
  15316. }
  15317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15318. isSuccess = ConfigurationStatus_Accepted;
  15319. }
  15320. else
  15321. {
  15322. isSuccess = ConfigurationStatus_Rejected;
  15323. }
  15324. }
  15325. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15326. {
  15327. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15328. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15329. {
  15330. strcpy(str, (const char*)value);
  15331. for(int i = 0; str[i]; i++){
  15332. str[i] = tolower(str[i]);
  15333. }
  15334. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15335. isSuccess = ConfigurationStatus_Accepted;
  15336. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15337. }
  15338. else
  15339. {
  15340. isSuccess = ConfigurationStatus_Rejected;
  15341. }
  15342. }
  15343. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15344. {
  15345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15346. {
  15347. strcpy(str, (const char*)value);
  15348. for(int i = 0; str[i]; i++)
  15349. {
  15350. str[i] = tolower(str[i]);
  15351. }
  15352. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15353. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15354. isSuccess = ConfigurationStatus_Accepted;
  15355. }
  15356. else
  15357. {
  15358. isSuccess = ConfigurationStatus_Rejected;
  15359. }
  15360. }
  15361. if(strcmp(key, "BlinkRepeat") == 0)
  15362. {
  15363. //Charger.BlinkRepeat = Integer.parseInt(value);
  15364. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15365. {
  15366. check_ascii = value[0];
  15367. if( (check_ascii < 48) || (check_ascii > 57) )
  15368. {
  15369. isSuccess = ConfigurationStatus_Rejected;
  15370. }
  15371. else
  15372. {
  15373. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15374. isSuccess = ConfigurationStatus_Accepted;
  15375. }
  15376. }
  15377. else
  15378. {
  15379. isSuccess = ConfigurationStatus_Rejected;
  15380. }
  15381. }
  15382. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15383. {
  15384. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15385. {
  15386. check_ascii = value[0];
  15387. if( (check_ascii < 48) || (check_ascii > 57) )
  15388. {
  15389. isSuccess = ConfigurationStatus_Rejected;
  15390. }
  15391. else
  15392. {
  15393. if((atoi(value) == 0) || (atoi(value) >= 5))
  15394. {
  15395. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15396. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15397. isSuccess = ConfigurationStatus_Accepted;
  15398. }
  15399. else
  15400. isSuccess = ConfigurationStatus_Rejected;
  15401. }
  15402. }
  15403. else
  15404. {
  15405. isSuccess = ConfigurationStatus_Rejected;
  15406. }
  15407. }
  15408. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15409. {
  15410. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15411. {
  15412. check_ascii = value[0];
  15413. if( (check_ascii < 48) || (check_ascii > 57) )
  15414. {
  15415. isSuccess = ConfigurationStatus_Rejected;
  15416. }
  15417. else
  15418. {
  15419. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15420. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15421. isSuccess = ConfigurationStatus_Accepted;
  15422. }
  15423. }
  15424. else
  15425. {
  15426. isSuccess = ConfigurationStatus_Rejected;
  15427. }
  15428. }
  15429. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15430. {
  15431. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15432. {
  15433. check_ascii = value[0];
  15434. if( (check_ascii < 48) || (check_ascii > 57) )
  15435. {
  15436. isSuccess = ConfigurationStatus_Rejected;
  15437. }
  15438. else
  15439. {
  15440. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15442. isSuccess = ConfigurationStatus_Accepted;
  15443. }
  15444. }
  15445. else
  15446. {
  15447. isSuccess = ConfigurationStatus_Rejected;
  15448. }
  15449. }
  15450. if(strcmp(key, "HeartbeatInterval") == 0)
  15451. {
  15452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15453. {
  15454. check_ascii = value[0];
  15455. if( (check_ascii < 48) || (check_ascii > 57) )
  15456. {
  15457. isSuccess = ConfigurationStatus_Rejected;
  15458. }
  15459. else
  15460. {
  15461. if((atoi(value) == 0) || (atoi(value) >= 10))
  15462. {
  15463. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15465. HeartBeatWaitTime = atoi(value);
  15466. isSuccess = ConfigurationStatus_Accepted;
  15467. }
  15468. else
  15469. {
  15470. isSuccess = ConfigurationStatus_Rejected;
  15471. }
  15472. }
  15473. }
  15474. else
  15475. {
  15476. isSuccess = ConfigurationStatus_Rejected;
  15477. }
  15478. }
  15479. if(strcmp(key, "LightIntensity") == 0)
  15480. {
  15481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15482. {
  15483. check_ascii = value[0];
  15484. if( (check_ascii < 48) || (check_ascii > 57) )
  15485. {
  15486. isSuccess = ConfigurationStatus_Rejected;
  15487. }
  15488. else
  15489. {
  15490. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15491. isSuccess = ConfigurationStatus_Accepted;
  15492. }
  15493. }
  15494. else
  15495. {
  15496. isSuccess = ConfigurationStatus_Rejected;
  15497. }
  15498. }
  15499. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15500. {
  15501. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15502. {
  15503. strcpy(str, (const char*)value);
  15504. for(int i = 0; str[i]; i++)
  15505. {
  15506. str[i] = tolower(str[i]);
  15507. }
  15508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15509. isSuccess = ConfigurationStatus_Accepted;
  15510. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15511. }
  15512. else
  15513. {
  15514. isSuccess = ConfigurationStatus_Rejected;
  15515. }
  15516. }
  15517. if(strcmp(key, "LocalPreAuthorize") == 0)
  15518. {
  15519. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15520. {
  15521. strcpy(str, (const char*)value);
  15522. for(int i = 0; str[i]; i++)
  15523. {
  15524. str[i] = tolower(str[i]);
  15525. }
  15526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15527. isSuccess = ConfigurationStatus_Accepted;
  15528. }
  15529. else
  15530. {
  15531. isSuccess = ConfigurationStatus_Rejected;
  15532. }
  15533. }
  15534. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15535. {
  15536. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15537. {
  15538. check_ascii = value[0];
  15539. if( (check_ascii < 48) || (check_ascii > 57) )
  15540. {
  15541. isSuccess = ConfigurationStatus_Rejected;
  15542. }
  15543. else
  15544. {
  15545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15546. isSuccess = ConfigurationStatus_Accepted;
  15547. }
  15548. }
  15549. else
  15550. {
  15551. isSuccess = ConfigurationStatus_Rejected;
  15552. }
  15553. }
  15554. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15555. {
  15556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15557. {
  15558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15559. isSuccess = ConfigurationStatus_Accepted;
  15560. }
  15561. else
  15562. {
  15563. isSuccess = ConfigurationStatus_Rejected;
  15564. }
  15565. }
  15566. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15567. {
  15568. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15569. {
  15570. check_ascii = value[0];
  15571. if( (check_ascii < 48) || (check_ascii > 57) )
  15572. {
  15573. isSuccess = ConfigurationStatus_Rejected;
  15574. }
  15575. else
  15576. {
  15577. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15579. isSuccess = ConfigurationStatus_Accepted;
  15580. }
  15581. }
  15582. else
  15583. {
  15584. isSuccess = ConfigurationStatus_Rejected;
  15585. }
  15586. }
  15587. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15588. {
  15589. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15590. {
  15591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15592. isSuccess = ConfigurationStatus_Accepted;
  15593. }
  15594. else
  15595. {
  15596. isSuccess = ConfigurationStatus_Rejected;
  15597. }
  15598. }
  15599. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15600. {
  15601. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15602. {
  15603. check_ascii = value[0];
  15604. if( (check_ascii < 48) || (check_ascii > 57) )
  15605. {
  15606. isSuccess = ConfigurationStatus_Rejected;
  15607. }
  15608. else
  15609. {
  15610. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15612. isSuccess = ConfigurationStatus_Accepted;
  15613. }
  15614. }
  15615. else
  15616. {
  15617. isSuccess = ConfigurationStatus_Rejected;
  15618. }
  15619. }
  15620. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15621. {
  15622. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15623. {
  15624. check_ascii = value[0];
  15625. if( (check_ascii < 48) || (check_ascii > 57) )
  15626. {
  15627. isSuccess = ConfigurationStatus_Rejected;
  15628. }
  15629. else
  15630. {
  15631. if((atoi(value) == 0) || (atoi(value) >= 3))
  15632. {
  15633. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15635. isSuccess = ConfigurationStatus_Accepted;
  15636. }
  15637. else
  15638. {
  15639. isSuccess = ConfigurationStatus_Rejected;
  15640. }
  15641. }
  15642. }
  15643. else
  15644. {
  15645. isSuccess = ConfigurationStatus_Rejected;
  15646. }
  15647. }
  15648. if(strcmp(key, "MinimumStatusDuration") == 0)
  15649. {
  15650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15651. {
  15652. check_ascii = value[0];
  15653. if( (check_ascii < 48) || (check_ascii > 57) )
  15654. {
  15655. isSuccess = ConfigurationStatus_Rejected;
  15656. }
  15657. else
  15658. {
  15659. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15660. {
  15661. isSuccess = ConfigurationStatus_Rejected;
  15662. }
  15663. else
  15664. {
  15665. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15667. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15668. isSuccess = ConfigurationStatus_Accepted;
  15669. }
  15670. }
  15671. }
  15672. else
  15673. {
  15674. isSuccess = ConfigurationStatus_Rejected;
  15675. }
  15676. }
  15677. if(strcmp(key, "NumberOfConnectors") == 0)
  15678. {
  15679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15680. {
  15681. check_ascii = value[0];
  15682. if( (check_ascii < 48) || (check_ascii > 57) )
  15683. {
  15684. isSuccess = ConfigurationStatus_Rejected;
  15685. }
  15686. else
  15687. {
  15688. //Charger.ResetRetries = Integer.parseInt(value);
  15689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15690. isSuccess = ConfigurationStatus_Accepted;
  15691. }
  15692. }
  15693. else
  15694. {
  15695. isSuccess = ConfigurationStatus_Rejected;
  15696. }
  15697. }
  15698. if(strcmp(key, "ResetRetries") == 0)
  15699. {
  15700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15701. {
  15702. check_ascii = value[0];
  15703. if( (check_ascii < 48) || (check_ascii > 57) )
  15704. {
  15705. isSuccess = ConfigurationStatus_Rejected;
  15706. }
  15707. else
  15708. {
  15709. //Charger.ResetRetries = Integer.parseInt(value);
  15710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15711. isSuccess = ConfigurationStatus_Accepted;
  15712. }
  15713. }
  15714. else
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. }
  15719. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15720. {
  15721. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15722. {
  15723. strcpy(str, (const char*)value);
  15724. for(int i = 0; str[i]; i++)
  15725. {
  15726. str[i] = tolower(str[i]);
  15727. }
  15728. if(strcmp(str, "notapplicable")== 0)
  15729. {
  15730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15731. isSuccess = ConfigurationStatus_Accepted;
  15732. }
  15733. else if(strcmp(str, "unknown")== 0)
  15734. {
  15735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15736. isSuccess = ConfigurationStatus_Accepted;
  15737. }
  15738. else if(strcmp(str, "rst")== 0)
  15739. {
  15740. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15741. isSuccess = ConfigurationStatus_Accepted;
  15742. }
  15743. else if(strcmp(str, "rts")== 0)
  15744. {
  15745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15746. isSuccess = ConfigurationStatus_Accepted;
  15747. }
  15748. else if(strcmp(str, "srt")== 0)
  15749. {
  15750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15751. isSuccess = ConfigurationStatus_Accepted;
  15752. }
  15753. else if(strcmp(str, "str")== 0)
  15754. {
  15755. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15756. isSuccess = ConfigurationStatus_Accepted;
  15757. }
  15758. else if(strcmp(str, "trs")== 0)
  15759. {
  15760. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15761. isSuccess = ConfigurationStatus_Accepted;
  15762. }
  15763. else if(strcmp(str, "tsr")== 0)
  15764. {
  15765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15766. isSuccess = ConfigurationStatus_Accepted;
  15767. }
  15768. else
  15769. {
  15770. isSuccess = ConfigurationStatus_Rejected;
  15771. }
  15772. }
  15773. else
  15774. {
  15775. isSuccess = ConfigurationStatus_Rejected;
  15776. }
  15777. }
  15778. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15779. {
  15780. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15781. {
  15782. check_ascii = value[0];
  15783. if( (check_ascii < 48) || (check_ascii > 57) )
  15784. {
  15785. isSuccess = ConfigurationStatus_Rejected;
  15786. }
  15787. else
  15788. {
  15789. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15790. isSuccess = ConfigurationStatus_Accepted;
  15791. }
  15792. }
  15793. else
  15794. {
  15795. isSuccess = ConfigurationStatus_Rejected;
  15796. }
  15797. }
  15798. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15799. {
  15800. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15801. {
  15802. strcpy(str, (const char*)value);
  15803. for(int i = 0; str[i]; i++)
  15804. {
  15805. str[i] = tolower(str[i]);
  15806. }
  15807. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15809. isSuccess = ConfigurationStatus_Accepted;
  15810. }
  15811. else
  15812. {
  15813. isSuccess = ConfigurationStatus_Rejected;
  15814. }
  15815. }
  15816. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15817. {
  15818. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15819. {
  15820. strcpy(str, (const char*)value);
  15821. for(int i = 0; str[i]; i++)
  15822. {
  15823. str[i] = tolower(str[i]);
  15824. }
  15825. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15826. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15827. isSuccess = ConfigurationStatus_Accepted;
  15828. }
  15829. else
  15830. {
  15831. isSuccess = ConfigurationStatus_Rejected;
  15832. }
  15833. }
  15834. if(strcmp(key, "StopTxnAlignedData") == 0)
  15835. {
  15836. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15837. {
  15838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15839. isSuccess = ConfigurationStatus_Accepted;
  15840. }
  15841. else
  15842. {
  15843. isSuccess = ConfigurationStatus_Rejected;
  15844. }
  15845. }
  15846. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15847. {
  15848. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15849. {
  15850. check_ascii = value[0];
  15851. if( (check_ascii < 48) || (check_ascii > 57) )
  15852. {
  15853. isSuccess = ConfigurationStatus_Rejected;
  15854. }
  15855. else
  15856. {
  15857. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15858. isSuccess = ConfigurationStatus_Accepted;
  15859. }
  15860. }
  15861. else
  15862. {
  15863. isSuccess = ConfigurationStatus_Rejected;
  15864. }
  15865. }
  15866. if(strcmp(key, "StopTxnSampledData") == 0)
  15867. {
  15868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15869. {
  15870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15871. isSuccess = ConfigurationStatus_Accepted;
  15872. }
  15873. else
  15874. {
  15875. isSuccess = ConfigurationStatus_Rejected;
  15876. }
  15877. }
  15878. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15879. {
  15880. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15881. {
  15882. check_ascii = value[0];
  15883. if( (check_ascii < 48) || (check_ascii > 57) )
  15884. {
  15885. isSuccess = ConfigurationStatus_Rejected;
  15886. }
  15887. else
  15888. {
  15889. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15890. isSuccess = ConfigurationStatus_Accepted;
  15891. }
  15892. }
  15893. else
  15894. {
  15895. isSuccess = ConfigurationStatus_Rejected;
  15896. }
  15897. }
  15898. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15899. {
  15900. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15901. {
  15902. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15903. isSuccess = ConfigurationStatus_Accepted;
  15904. }
  15905. else
  15906. {
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15911. {
  15912. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15913. {
  15914. check_ascii = value[0];
  15915. if( (check_ascii < 48) || (check_ascii > 57) )
  15916. {
  15917. isSuccess = ConfigurationStatus_Rejected;
  15918. }
  15919. else
  15920. {
  15921. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15922. isSuccess = ConfigurationStatus_Accepted;
  15923. }
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15931. {
  15932. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15933. {
  15934. check_ascii = value[0];
  15935. if( (check_ascii < 48) || (check_ascii > 57) )
  15936. {
  15937. isSuccess = ConfigurationStatus_Rejected;
  15938. }
  15939. else
  15940. {
  15941. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15942. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15943. TransactionMessageAttemptsValue = atoi(value);
  15944. isSuccess = ConfigurationStatus_Accepted;
  15945. }
  15946. }
  15947. else
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. }
  15952. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15953. {
  15954. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15955. {
  15956. check_ascii = value[0];
  15957. if( (check_ascii < 48) || (check_ascii > 57) )
  15958. {
  15959. isSuccess = ConfigurationStatus_Rejected;
  15960. }
  15961. else
  15962. {
  15963. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15964. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15965. TransactionMessageRetryIntervalValue = atoi(value);
  15966. isSuccess = ConfigurationStatus_Accepted;
  15967. }
  15968. }
  15969. else
  15970. {
  15971. isSuccess = ConfigurationStatus_Rejected;
  15972. }
  15973. }
  15974. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15975. {
  15976. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15977. {
  15978. strcpy(str, (const char*)value);
  15979. for(int i = 0; str[i]; i++)
  15980. {
  15981. str[i] = tolower(str[i]);
  15982. }
  15983. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15984. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15985. isSuccess = ConfigurationStatus_Accepted;
  15986. }
  15987. else
  15988. {
  15989. isSuccess = ConfigurationStatus_Rejected;
  15990. }
  15991. }
  15992. if(strcmp(key, "WebSocketPingInterval") == 0)
  15993. {
  15994. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15995. {
  15996. check_ascii = value[0];
  15997. if( (check_ascii < 48) || (check_ascii > 57) )
  15998. {
  15999. isSuccess = ConfigurationStatus_Rejected;
  16000. }
  16001. else
  16002. {
  16003. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16004. isSuccess = ConfigurationStatus_Accepted;
  16005. if((atoi(value) == 0) || (atoi(value) >= 10))
  16006. {
  16007. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16008. isSuccess = ConfigurationStatus_Accepted;
  16009. }
  16010. else
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. else
  16015. {
  16016. isSuccess = ConfigurationStatus_Rejected;
  16017. }
  16018. }
  16019. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16020. {
  16021. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16022. {
  16023. strcpy(str, (const char*)value);
  16024. for(int i = 0; str[i]; i++)
  16025. {
  16026. str[i] = tolower(str[i]);
  16027. }
  16028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16029. isSuccess = ConfigurationStatus_Accepted;
  16030. }
  16031. else
  16032. {
  16033. isSuccess = ConfigurationStatus_Rejected;
  16034. }
  16035. }
  16036. if(strcmp(key, "AuthorizationKey") == 0)
  16037. {
  16038. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16039. {
  16040. strcpy(str, (const char*)value);
  16041. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16042. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16043. isSuccess = ConfigurationStatus_Accepted;
  16044. }
  16045. else
  16046. {
  16047. isSuccess = ConfigurationStatus_Rejected;
  16048. }
  16049. }
  16050. if(strcmp(key, "SecurityProfile") == 0)
  16051. {
  16052. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16053. {
  16054. check_ascii = value[0];
  16055. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16056. {
  16057. isSuccess = ConfigurationStatus_Rejected;
  16058. }
  16059. else if(check_ascii == 0x33)
  16060. {
  16061. isSuccess = NotSupported;
  16062. }
  16063. else
  16064. {
  16065. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16066. {
  16067. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16068. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16069. isSuccess = ConfigurationStatus_Accepted;
  16070. }
  16071. else
  16072. isSuccess = ConfigurationStatus_Rejected;
  16073. }
  16074. }
  16075. else
  16076. {
  16077. isSuccess = ConfigurationStatus_Rejected;
  16078. }
  16079. }
  16080. if(strcmp(key, "DefaultPrice") == 0)
  16081. {
  16082. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16083. {
  16084. strcpy(str, (const char*)value);
  16085. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16086. isSuccess = ConfigurationStatus_Accepted;
  16087. }
  16088. else
  16089. {
  16090. isSuccess = ConfigurationStatus_Rejected;
  16091. }
  16092. }
  16093. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16094. {
  16095. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16096. {
  16097. strcpy(str, (const char*)value);
  16098. for(int i = 0; str[i]; i++)
  16099. {
  16100. str[i] = tolower(str[i]);
  16101. }
  16102. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16103. isSuccess = ConfigurationStatus_Accepted;
  16104. }
  16105. else
  16106. {
  16107. isSuccess = ConfigurationStatus_Rejected;
  16108. }
  16109. }
  16110. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16111. {
  16112. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16113. {
  16114. strcpy(str, (const char*)value);
  16115. for(int i = 0; str[i]; i++)
  16116. {
  16117. str[i] = tolower(str[i]);
  16118. }
  16119. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16120. isSuccess = ConfigurationStatus_Accepted;
  16121. }
  16122. else
  16123. {
  16124. isSuccess = ConfigurationStatus_Rejected;
  16125. }
  16126. }
  16127. if(strcmp(key, "SystemUptimeSec") == 0)
  16128. {
  16129. isSuccess = NotSupported;
  16130. }
  16131. if(strcmp(key, "FreeVend") == 0)
  16132. {
  16133. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16134. {
  16135. strcpy(str, (const char*)value);
  16136. for(int i = 0; str[i]; i++)
  16137. {
  16138. str[i] = tolower(str[i]);
  16139. }
  16140. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16141. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16142. isSuccess = ConfigurationStatus_Accepted;
  16143. }
  16144. else
  16145. {
  16146. isSuccess = ConfigurationStatus_Rejected;
  16147. }
  16148. }
  16149. if(strcmp(key, "FreeVendIdtag") == 0)
  16150. {
  16151. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16152. {
  16153. strcpy(str, (const char*)value);
  16154. if(strlen(str) <= 20)
  16155. {
  16156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16157. isSuccess = ConfigurationStatus_Accepted;
  16158. }
  16159. else
  16160. {
  16161. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16162. isSuccess = ConfigurationStatus_Rejected;
  16163. }
  16164. }
  16165. else
  16166. {
  16167. isSuccess = ConfigurationStatus_Rejected;
  16168. }
  16169. }
  16170. if(strcmp(key, "OcppServer") == 0)
  16171. {
  16172. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16173. {
  16174. strcpy(str, (const char*)value);
  16175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16176. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16177. isSuccess = ConfigurationStatus_Accepted;
  16178. }
  16179. else
  16180. {
  16181. isSuccess = ConfigurationStatus_Rejected;
  16182. }
  16183. }
  16184. if(strcmp(key, "MaintainServer") == 0)
  16185. {
  16186. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16187. {
  16188. strcpy(str, (const char*)value);
  16189. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16190. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16191. isSuccess = ConfigurationStatus_Accepted;
  16192. }
  16193. else
  16194. {
  16195. isSuccess = ConfigurationStatus_Rejected;
  16196. }
  16197. }
  16198. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16199. {
  16200. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16201. {
  16202. strcpy(str, (const char*)value);
  16203. for(int i = 0; str[i]; i++)
  16204. {
  16205. str[i] = tolower(str[i]);
  16206. }
  16207. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16208. isSuccess = ConfigurationStatus_Accepted;
  16209. }
  16210. else
  16211. {
  16212. isSuccess = ConfigurationStatus_Rejected;
  16213. }
  16214. }
  16215. if(strcmp(key, "StatusNotificationInterval") == 0)
  16216. {
  16217. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16218. {
  16219. check_ascii = value[0];
  16220. if( (check_ascii < 48) || (check_ascii > 57) )
  16221. {
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. else
  16225. {
  16226. if((atoi(value) == 0) || (atoi(value) >= 10))
  16227. {
  16228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16229. isSuccess = ConfigurationStatus_Accepted;
  16230. }
  16231. else
  16232. isSuccess = ConfigurationStatus_Rejected;
  16233. }
  16234. }
  16235. else
  16236. {
  16237. isSuccess = ConfigurationStatus_Rejected;
  16238. }
  16239. }
  16240. #if 0
  16241. //For OCPP Test Case
  16242. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16243. {
  16244. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16245. {
  16246. strcpy(str, (const char*)value);
  16247. for(int i = 0; str[i]; i++)
  16248. {
  16249. str[i] = tolower(str[i]);
  16250. }
  16251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16252. isSuccess = ConfigurationStatus_Accepted;
  16253. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16254. }
  16255. else
  16256. {
  16257. isSuccess = ConfigurationStatus_Rejected;
  16258. }
  16259. }
  16260. #endif
  16261. #if 1
  16262. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16263. {
  16264. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16265. {
  16266. strcpy(str, (const char*)value);
  16267. for(int i = 0; str[i]; i++)
  16268. {
  16269. str[i] = tolower(str[i]);
  16270. }
  16271. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16272. isSuccess = ConfigurationStatus_Accepted;
  16273. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16274. }
  16275. else
  16276. {
  16277. isSuccess = ConfigurationStatus_Rejected;
  16278. }
  16279. }
  16280. #endif
  16281. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16282. {
  16283. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16284. {
  16285. check_ascii = value[0];
  16286. if( (check_ascii < 48) || (check_ascii > 57) )
  16287. {
  16288. isSuccess = ConfigurationStatus_Rejected;
  16289. }
  16290. else
  16291. {
  16292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16293. isSuccess = ConfigurationStatus_Accepted;
  16294. }
  16295. }
  16296. else
  16297. {
  16298. isSuccess = ConfigurationStatus_Rejected;
  16299. }
  16300. }
  16301. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16302. {
  16303. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16304. {
  16305. check_ascii = value[0];
  16306. if( (check_ascii < 48) || (check_ascii > 57) )
  16307. {
  16308. isSuccess = ConfigurationStatus_Rejected;
  16309. }
  16310. else
  16311. {
  16312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16313. isSuccess = ConfigurationStatus_Accepted;
  16314. }
  16315. }
  16316. else
  16317. {
  16318. isSuccess = ConfigurationStatus_Rejected;
  16319. }
  16320. }
  16321. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16322. {
  16323. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16324. {
  16325. strcpy(str, (const char*)value);
  16326. for(int i = 0; str[i]; i++)
  16327. {
  16328. str[i] = tolower(str[i]);
  16329. }
  16330. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16331. isSuccess = ConfigurationStatus_Accepted;
  16332. }
  16333. else
  16334. {
  16335. isSuccess = ConfigurationStatus_Rejected;
  16336. }
  16337. }
  16338. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16339. {
  16340. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16341. {
  16342. check_ascii = value[0];
  16343. if( (check_ascii < 48) || (check_ascii > 57) )
  16344. {
  16345. isSuccess = ConfigurationStatus_Rejected;
  16346. }
  16347. else
  16348. {
  16349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16350. isSuccess = ConfigurationStatus_Accepted;
  16351. }
  16352. }
  16353. else
  16354. {
  16355. isSuccess = ConfigurationStatus_Rejected;
  16356. }
  16357. }
  16358. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16359. {
  16360. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16361. {
  16362. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16363. isSuccess = ConfigurationStatus_Accepted;
  16364. }
  16365. else
  16366. {
  16367. isSuccess = ConfigurationStatus_Rejected;
  16368. }
  16369. }
  16370. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16371. {
  16372. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16373. {
  16374. check_ascii = value[0];
  16375. if( (check_ascii < 48) || (check_ascii > 57) )
  16376. {
  16377. isSuccess = ConfigurationStatus_Rejected;
  16378. }
  16379. else
  16380. {
  16381. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16382. isSuccess = ConfigurationStatus_Accepted;
  16383. }
  16384. }
  16385. else
  16386. {
  16387. isSuccess = ConfigurationStatus_Rejected;
  16388. }
  16389. }
  16390. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16391. {
  16392. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16393. {
  16394. strcpy(str, (const char*)value);
  16395. for(int i = 0; str[i]; i++)
  16396. {
  16397. str[i] = tolower(str[i]);
  16398. }
  16399. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16400. isSuccess = ConfigurationStatus_Accepted;
  16401. }
  16402. else
  16403. {
  16404. isSuccess = ConfigurationStatus_Rejected;
  16405. }
  16406. }
  16407. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16408. {
  16409. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16410. {
  16411. check_ascii = value[0];
  16412. if( (check_ascii < 48) || (check_ascii > 57) )
  16413. {
  16414. isSuccess = ConfigurationStatus_Rejected;
  16415. }
  16416. else
  16417. {
  16418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16419. isSuccess = ConfigurationStatus_Accepted;
  16420. }
  16421. }
  16422. else
  16423. {
  16424. isSuccess = ConfigurationStatus_Rejected;
  16425. }
  16426. }
  16427. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16428. return isSuccess;
  16429. }
  16430. int TransactionMessageAttemptsGet(void)
  16431. {
  16432. return TransactionMessageAttemptsValue;
  16433. }
  16434. int FirstHeartBeatResponse(void)
  16435. {
  16436. return FirstHeartBeat;
  16437. }
  16438. int TransactionMessageRetryIntervalGet(void)
  16439. {
  16440. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16441. }
  16442. int ReadHttpStatus(int sock)
  16443. {
  16444. //char c;
  16445. char buff[1024]="",*ptr=buff+1;
  16446. int bytes_received, status;
  16447. DEBUG_INFO("Begin Response ..\n");
  16448. while((bytes_received = recv(sock, ptr, 1, 0))){
  16449. if(bytes_received==-1){
  16450. perror("ReadHttpStatus");
  16451. exit(1);
  16452. }
  16453. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16454. ptr++;
  16455. }
  16456. *ptr=0;
  16457. ptr=buff+1;
  16458. sscanf(ptr,"%*s %d ", &status);
  16459. DEBUG_INFO("%s\n",ptr);
  16460. DEBUG_INFO("status=%d\n",status);
  16461. DEBUG_INFO("End Response ..\n");
  16462. return (bytes_received>0)?status:0;
  16463. }
  16464. //the only filed that it parsed is 'Content-Length'
  16465. int ParseHeader(int sock)
  16466. {
  16467. //char c;
  16468. char buff[1024]="",*ptr=buff+4;
  16469. int bytes_received;
  16470. DEBUG_INFO("Begin HEADER ..\n");
  16471. while((bytes_received = recv(sock, ptr, 1, 0))){
  16472. if(bytes_received==-1){
  16473. perror("Parse Header");
  16474. exit(1);
  16475. }
  16476. if(
  16477. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16478. (ptr[-1]=='\r') && (*ptr=='\n' )
  16479. ) break;
  16480. ptr++;
  16481. }
  16482. *ptr=0;
  16483. ptr=buff+4;
  16484. //printf("%s",ptr);
  16485. if(bytes_received){
  16486. ptr=strstr(ptr,"Content-Length:");
  16487. if(ptr){
  16488. sscanf(ptr,"%*s %d",&bytes_received);
  16489. }else
  16490. bytes_received=-1; //unknown size
  16491. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16492. }
  16493. DEBUG_INFO("End HEADER ..\n");
  16494. return bytes_received ;
  16495. }
  16496. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16497. {
  16498. int result = TRUE;
  16499. char rmFileCmd[100]={0};
  16500. char FilePath[100]={0};
  16501. char ftpbuf[200];
  16502. int systemresult;
  16503. sprintf(FilePath,"/mnt/%s",filename);
  16504. system("ping 8.8.8.8 &");
  16505. if((access(FilePath,F_OK))!=-1)
  16506. {
  16507. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16508. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16509. system(rmFileCmd);
  16510. }
  16511. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16512. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16513. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16514. systemresult = system(ftpbuf);
  16515. if(systemresult != 0)
  16516. {
  16517. DEBUG_INFO("http DownLoad error!\n");
  16518. result = FALSE;
  16519. }
  16520. system("pkill ping");
  16521. return result;
  16522. }
  16523. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16524. {
  16525. int result = TRUE;
  16526. char rmFileCmd[100]={0};
  16527. char FilePath[100]={0};
  16528. char ftpbuf[200];
  16529. int systemresult;
  16530. sprintf(FilePath,"/mnt/%s",filename);
  16531. system("ping 8.8.8.8 &");
  16532. if((access(FilePath,F_OK))!=-1)
  16533. {
  16534. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16535. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16536. system(rmFileCmd);
  16537. }
  16538. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16539. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16540. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16541. systemresult = system(ftpbuf);
  16542. if(systemresult != 0)
  16543. {
  16544. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16545. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16546. systemresult = system(ftpbuf);
  16547. if(systemresult != 0)
  16548. {
  16549. DEBUG_WARN("wget error!\n");
  16550. result = FALSE;
  16551. }
  16552. }
  16553. system("pkill ping");
  16554. return result;
  16555. }
  16556. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16557. {
  16558. char rmFileCmd[100]={0};
  16559. char FilePath[100]={0};
  16560. char buf[512];
  16561. int systemresult = 0;
  16562. //DEBUG_INFO("filename=%s\n",filename);
  16563. //DEBUG_INFO("url=%s\n",url);
  16564. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16565. if((access(FilePath,F_OK))!=-1)
  16566. {
  16567. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16568. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16569. system(rmFileCmd);
  16570. }
  16571. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16572. if(fp == NULL)
  16573. {
  16574. DEBUG_INFO("log is NULL\n");
  16575. return FALSE;
  16576. }
  16577. else
  16578. {
  16579. fprintf(fp, "%s\n", url);
  16580. fprintf(fp, "%s\n", filename);
  16581. fclose(fp);
  16582. }
  16583. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16584. if(phpFP == NULL)
  16585. {
  16586. DEBUG_INFO("PHP upload fail.\n");
  16587. return FALSE;
  16588. }
  16589. else
  16590. {
  16591. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16592. {
  16593. if(strstr(buf, "result") != NULL)
  16594. {
  16595. sscanf(buf, "result: %d", &systemresult);
  16596. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16597. }
  16598. }
  16599. pclose(phpFP);
  16600. }
  16601. if(systemresult != 1)
  16602. {
  16603. DEBUG_INFO("HTTP upload error!\n");
  16604. return FALSE;
  16605. }
  16606. return TRUE;
  16607. }
  16608. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16609. {
  16610. int result = FALSE;
  16611. char ftpbuf[200];
  16612. int systemresult;
  16613. /*
  16614. // Domaind name transfer to IP address
  16615. struct hostent* server;
  16616. char *IPbuffer;
  16617. server = gethostbyname(location);
  16618. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16619. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16620. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16621. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16622. systemresult = system(ftpbuf);
  16623. if(systemresult != 0)
  16624. {
  16625. DEBUG_INFO("ftpput error!\n");
  16626. }
  16627. else
  16628. {
  16629. result = TRUE;
  16630. DEBUG_INFO("ftpput OK!\n");
  16631. }
  16632. return result;
  16633. }
  16634. int GetOcppServerURL()
  16635. {
  16636. int result = FALSE;
  16637. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16638. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16639. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16640. struct yuarel url;
  16641. char urlStr[512];
  16642. // OCPPPH only
  16643. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16644. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16645. {
  16646. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16647. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16648. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16649. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16650. if(yuarel_parse(&url, urlStr) != -1)
  16651. {
  16652. sprintf(OcppProtocol, "%s", url.scheme);
  16653. sprintf(OcppHost, "%s", url.host);
  16654. if(url.path == NULL)
  16655. OcppTempPath[0] = '\0';
  16656. else
  16657. sprintf(OcppTempPath, "%s", url.path);
  16658. if(url.port == 0)
  16659. {
  16660. if(strcmp(OcppProtocol, "wss") == 0)
  16661. OcppPort = 443;
  16662. else
  16663. OcppPort = 80;
  16664. }
  16665. else
  16666. OcppPort = url.port;
  16667. result = TRUE;
  16668. }
  16669. }
  16670. else
  16671. {
  16672. strcpy(OcppHost,"");
  16673. }
  16674. return result;
  16675. }
  16676. int GetOcppPath()
  16677. {
  16678. int result = FALSE;
  16679. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16680. {
  16681. if(OcppTempPath == NULL)
  16682. {
  16683. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16684. }
  16685. else
  16686. {
  16687. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16688. }
  16689. result = TRUE;
  16690. goto End;
  16691. }
  16692. else
  16693. {
  16694. strcpy(OcppPath,"");
  16695. }
  16696. End:
  16697. return result;
  16698. }
  16699. int GetOcppPort()
  16700. {
  16701. return OcppPort;
  16702. }
  16703. int GetOcppConnStatus(void)
  16704. {
  16705. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16706. }
  16707. void SetOcppConnStatus(uint8_t status)
  16708. {
  16709. ShmOCPP16DataPH->OcppConnStatus = status;
  16710. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16711. }
  16712. int GetHeartBeatWithNOResponse(void)
  16713. {
  16714. return HeartBeatWithNOResponse;
  16715. }
  16716. void SetHeartBeatWithNOResponse(void)
  16717. {
  16718. HeartBeatWithNOResponse = 0;
  16719. }
  16720. void GetStartTransactionIdTag(int gun_index)
  16721. {
  16722. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16723. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16724. }
  16725. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16726. {
  16727. char ch;
  16728. FILE *fptr1;
  16729. int temptransactionId;
  16730. char str[100]={0};
  16731. temptransactionId = 0;
  16732. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16733. {
  16734. DEBUG_INFO("IdTag is empty.\n");
  16735. return temptransactionId;
  16736. }
  16737. /*------ Read the file ----------------*/
  16738. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16739. if (!fptr1)
  16740. {
  16741. DEBUG_INFO("QueueTransactionId file open error.\n");
  16742. //printf(" File not found or unable to open the input file!!\n");
  16743. return temptransactionId;
  16744. }
  16745. ch=fgetc(fptr1);
  16746. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16747. rewind(fptr1);
  16748. if(ch!=EOF)
  16749. {
  16750. // printf("%c",ch);
  16751. while (fgets(str, 100, fptr1) != NULL)
  16752. {
  16753. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16754. if(str[0]=='\0')
  16755. {
  16756. break;
  16757. }
  16758. char *revbuf[8] = {0}; // Variable store string split
  16759. int num = 0;// Quantity after string split
  16760. DEBUG_INFO("Transaction queue data= %s\n", str);
  16761. splitstring(str,",",revbuf,&num); // String split
  16762. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16763. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16764. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16765. DEBUG_INFO("------------------------------\n");
  16766. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16767. {
  16768. if(isStopTransaction)
  16769. {
  16770. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16771. {
  16772. temptransactionId = atoi(revbuf[2]);
  16773. //break;
  16774. }
  16775. }
  16776. else
  16777. {
  16778. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16779. {
  16780. temptransactionId = atoi(revbuf[2]);
  16781. //break;
  16782. }
  16783. }
  16784. }
  16785. }
  16786. }
  16787. else
  16788. DEBUG_INFO("EOF\n");
  16789. fclose(fptr1);
  16790. /*------- End of reading ---------------*/
  16791. return temptransactionId;
  16792. }
  16793. void SetTransactionIdZero(int transactionId)
  16794. {
  16795. char ch;
  16796. FILE *fptr1, *fptr2;
  16797. int temptransactionId = 0;
  16798. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16799. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16800. if (!fptr1)
  16801. {
  16802. //printf(" File not found or unable to open the input file!!\n");
  16803. return ;
  16804. }
  16805. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16806. if (!fptr2)
  16807. {
  16808. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16809. fclose(fptr1);
  16810. return ;
  16811. }
  16812. ch=fgetc(fptr1);
  16813. rewind(fptr1);
  16814. if(ch!=EOF)
  16815. {
  16816. // copy all contents to the temporary file except the specific line
  16817. while (fgets(str, 100, fptr1) != NULL)
  16818. {
  16819. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16820. if(str[0]=='\0')
  16821. {
  16822. break;
  16823. }
  16824. char *revbuf[8] = {0};
  16825. int num = 0;
  16826. strcpy(strtemp, str);
  16827. splitstring(str,",",revbuf,&num);
  16828. if(revbuf[2][0] != '\0')
  16829. {
  16830. temptransactionId = atoi(revbuf[2]);
  16831. if(transactionId != temptransactionId)
  16832. {
  16833. fprintf(fptr2, "%s\n", strtemp);
  16834. }
  16835. }
  16836. }
  16837. }
  16838. fclose(fptr1);
  16839. fclose(fptr2);
  16840. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16841. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16842. /*------ Read the file ----------------*/
  16843. }
  16844. int InternetDisconnect(void)
  16845. {
  16846. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16847. }
  16848. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16849. void storeTempStopTransaction(int gun_index)
  16850. {
  16851. char guid[37]={0};
  16852. int tempIndex = 0;
  16853. char TempStopTransaction[256];
  16854. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16855. DEBUG_INFO("storeTempStopTransaction...\n");
  16856. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16857. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16858. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16859. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16860. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16861. {
  16862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16863. {
  16864. tempIndex = ((gun_index==2) ? 1: 0);
  16865. }
  16866. else
  16867. {
  16868. tempIndex = gun_index;
  16869. }
  16870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16871. {
  16872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16873. {
  16874. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16875. }
  16876. }// END OF CHAdeMO_QUANTITY
  16877. }
  16878. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16879. {
  16880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16881. {
  16882. tempIndex = ((gun_index==2) ? 1: 0);
  16883. }
  16884. else
  16885. {
  16886. tempIndex = gun_index;
  16887. }
  16888. for (int index = 0; index < CCS_QUANTITY; index++)
  16889. {
  16890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16891. {
  16892. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16893. }
  16894. }// END OF CCS_QUANTITY
  16895. }
  16896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16897. {
  16898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16899. {
  16900. tempIndex = ((gun_index==2) ? 1: 0);
  16901. }
  16902. else
  16903. {
  16904. tempIndex = gun_index;
  16905. }
  16906. for (int index = 0; index < GB_QUANTITY; index++)
  16907. {
  16908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16909. {
  16910. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16911. }
  16912. }// END OF GB_QUANTITY
  16913. }
  16914. else if(gunType[gun_index] == GUN_TYPE_DO)
  16915. {
  16916. tempIndex = gun_index;
  16917. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16918. {
  16919. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16920. {
  16921. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16922. }
  16923. }
  16924. }
  16925. else
  16926. {
  16927. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16928. {
  16929. tempIndex = 2;
  16930. }
  16931. else
  16932. {
  16933. tempIndex = gun_index;
  16934. }
  16935. for (int index = 0; index < AC_QUANTITY; index++)
  16936. {
  16937. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16938. {
  16939. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16940. }
  16941. }// END OF AC_QUANTITY
  16942. }
  16943. //Stop Transaction Time
  16944. struct timeval tmnow;
  16945. struct tm *tm;
  16946. char buf[28];//, usec_buf[6];
  16947. gettimeofday(&tmnow, NULL);
  16948. time_t t;
  16949. t = time(NULL);
  16950. /*UTC time and date*/
  16951. tm = gmtime(&t);
  16952. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16954. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16956. random_uuid(guid);
  16957. /***********************************transactionData******************************************************/
  16958. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16960. //=================================
  16961. //1. Transaction_Begin
  16962. //=================================
  16963. //============================== Energy.Active.Import.Interval ===========================================
  16964. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16965. {
  16966. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16969. 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*/]);
  16970. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16971. 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))
  16972. {
  16973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16974. }
  16975. else
  16976. {
  16977. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16978. }
  16979. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16981. }
  16982. //=================================
  16983. //2. Transaction_End
  16984. //=================================
  16985. //2.1====================================== Current.Import L1 ==============================================
  16986. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16987. {
  16988. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16989. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16990. {
  16991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16992. {
  16993. tempIndex = ((gun_index==2) ? 1: 0);
  16994. }
  16995. else
  16996. {
  16997. tempIndex = gun_index;
  16998. }
  16999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17000. {
  17001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17002. {
  17003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17004. }
  17005. }// End of for CHAdeMO_QUANTITY
  17006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17007. }
  17008. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17009. {
  17010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17011. {
  17012. tempIndex = ((gun_index==2) ? 1: 0);
  17013. }
  17014. else
  17015. {
  17016. tempIndex = gun_index;
  17017. }
  17018. for (int index = 0; index < CCS_QUANTITY; index++)
  17019. {
  17020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17021. {
  17022. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17023. }
  17024. }// End of for CCS_QUANTITY
  17025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17026. }
  17027. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17028. {
  17029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17030. {
  17031. tempIndex = ((gun_index==2) ? 1: 0);
  17032. }
  17033. else
  17034. {
  17035. tempIndex = gun_index;
  17036. }
  17037. for (int index = 0; index < GB_QUANTITY; index++)
  17038. {
  17039. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17040. {
  17041. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17042. }
  17043. }// End of for GB_QUANTITY
  17044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17045. }
  17046. else if(gunType[gun_index] == GUN_TYPE_DO)
  17047. {
  17048. tempIndex = gun_index;
  17049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17050. {
  17051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17052. {
  17053. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17054. }
  17055. }
  17056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17057. }
  17058. else
  17059. {
  17060. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17061. {
  17062. tempIndex = 2;
  17063. }
  17064. else
  17065. {
  17066. tempIndex = gun_index;
  17067. }
  17068. for (int index = 0; index < AC_QUANTITY; index++)
  17069. {
  17070. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17071. {
  17072. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17073. }
  17074. }// End of for AC_QUANTITY
  17075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17076. }
  17077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17078. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17080. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17083. }
  17084. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17085. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17086. {
  17087. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17088. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17089. {
  17090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17091. {
  17092. tempIndex = ((gun_index==2) ? 1: 0);
  17093. }
  17094. else
  17095. {
  17096. tempIndex = gun_index;
  17097. }
  17098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17099. {
  17100. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17101. {
  17102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17103. }
  17104. }// END OF CHAdeMO_QUANTITY
  17105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17106. }
  17107. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17108. {
  17109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17110. {
  17111. tempIndex = ((gun_index==2) ? 1: 0);
  17112. }
  17113. else
  17114. {
  17115. tempIndex = gun_index;
  17116. }
  17117. for (int index = 0; index < CCS_QUANTITY; index++)
  17118. {
  17119. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17120. {
  17121. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17122. }
  17123. }// END OF CCS_QUANTITY
  17124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17125. }
  17126. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17127. {
  17128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17129. {
  17130. tempIndex = ((gun_index==2) ? 1: 0);
  17131. }
  17132. else
  17133. {
  17134. tempIndex = gun_index;
  17135. }
  17136. for (int index = 0; index < GB_QUANTITY; index++)
  17137. {
  17138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17139. {
  17140. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17141. }
  17142. }// END OF GB_QUANTITY
  17143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17144. }
  17145. else if(gunType[gun_index] == GUN_TYPE_DO)
  17146. {
  17147. tempIndex = gun_index;
  17148. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17149. {
  17150. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17151. {
  17152. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17153. }
  17154. }
  17155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17156. }
  17157. else
  17158. {
  17159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17160. {
  17161. tempIndex = 2;
  17162. }
  17163. else
  17164. {
  17165. tempIndex = gun_index;
  17166. }
  17167. for (int index = 0; index < AC_QUANTITY; index++)
  17168. {
  17169. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17170. {
  17171. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17172. }
  17173. }// END OF AC_QUANTITY
  17174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17175. }
  17176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17179. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17182. }
  17183. //2.3====================================== Power.Active.Import =========================================
  17184. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17185. {
  17186. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17187. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17188. {
  17189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17190. {
  17191. tempIndex = ((gun_index==2) ? 1: 0);
  17192. }
  17193. else
  17194. {
  17195. tempIndex = gun_index;
  17196. }
  17197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17198. {
  17199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17200. {
  17201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17202. }
  17203. } // End for CHAdeMO_QUANTITY
  17204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17205. }
  17206. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17207. {
  17208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17209. {
  17210. tempIndex = ((gun_index==2) ? 1: 0);
  17211. }
  17212. else
  17213. {
  17214. tempIndex = gun_index;
  17215. }
  17216. for (int index = 0; index < CCS_QUANTITY; index++)
  17217. {
  17218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17219. {
  17220. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17221. }
  17222. } // END for CCS_QUANTITY
  17223. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17224. }
  17225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17226. {
  17227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17228. {
  17229. tempIndex = ((gun_index==2) ? 1: 0);
  17230. }
  17231. else
  17232. {
  17233. tempIndex = gun_index;
  17234. }
  17235. for (int index = 0; index < GB_QUANTITY; index++)
  17236. {
  17237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17238. {
  17239. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17240. }
  17241. }// END for GB_QUANTITY
  17242. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17243. }
  17244. else if(gunType[gun_index] == GUN_TYPE_DO)
  17245. {
  17246. tempIndex = gun_index;
  17247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17248. {
  17249. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17250. {
  17251. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17252. }
  17253. }
  17254. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17255. }
  17256. else
  17257. {
  17258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17259. {
  17260. tempIndex = 2;
  17261. }
  17262. else
  17263. {
  17264. tempIndex = gun_index;
  17265. }
  17266. for (int index = 0; index < AC_QUANTITY; index++)
  17267. {
  17268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17269. {
  17270. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17271. }
  17272. } // END for AC_QUANTITY
  17273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17274. }
  17275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17278. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17281. }
  17282. //2.4====================================== Voltage L1 ====================================================
  17283. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17284. {
  17285. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17286. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17287. {
  17288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17289. {
  17290. tempIndex = ((gun_index==2) ? 1: 0);
  17291. }
  17292. else
  17293. {
  17294. tempIndex = gun_index;
  17295. }
  17296. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17297. {
  17298. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17299. {
  17300. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17301. }
  17302. } // END OF FOR CHAdeMO_QUANTITY
  17303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17304. }
  17305. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17306. {
  17307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17308. {
  17309. tempIndex = ((gun_index==2) ? 1: 0);
  17310. }
  17311. else
  17312. {
  17313. tempIndex = gun_index;
  17314. }
  17315. for (int index = 0; index < CCS_QUANTITY; index++)
  17316. {
  17317. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17318. {
  17319. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17320. }
  17321. } // END OF FOR CCS_QUANTITY
  17322. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17323. }
  17324. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17325. {
  17326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17327. {
  17328. tempIndex = ((gun_index==2) ? 1: 0);
  17329. }
  17330. else
  17331. {
  17332. tempIndex = gun_index;
  17333. }
  17334. for (int index = 0; index < GB_QUANTITY; index++)
  17335. {
  17336. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17337. {
  17338. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17339. }
  17340. } // END OF FOR GB_QUANTITY
  17341. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17342. }
  17343. else if(gunType[gun_index] == GUN_TYPE_DO)
  17344. {
  17345. tempIndex = gun_index;
  17346. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17347. {
  17348. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17349. {
  17350. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17351. }
  17352. }
  17353. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17354. }
  17355. else
  17356. {
  17357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17358. {
  17359. tempIndex = 2;
  17360. }
  17361. else
  17362. {
  17363. tempIndex = gun_index;
  17364. }
  17365. for (int index = 0; index < AC_QUANTITY; index++)
  17366. {
  17367. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17368. {
  17369. 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
  17370. }
  17371. } // END OF FOR AC_QUANTITY
  17372. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17373. }
  17374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17375. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17376. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17377. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17380. }
  17381. //2.5============================================== End SoC =========================================================
  17382. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17383. {
  17384. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17385. 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))
  17386. {
  17387. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17388. {
  17389. tempIndex = ((gun_index==2) ? 1: 0);
  17390. }
  17391. else
  17392. {
  17393. tempIndex = gun_index;
  17394. }
  17395. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17396. {
  17397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17398. {
  17399. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17400. {
  17401. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17402. }
  17403. }
  17404. }
  17405. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17406. {
  17407. for (int index = 0; index < CCS_QUANTITY; index++)
  17408. {
  17409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17410. {
  17411. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17412. }
  17413. }
  17414. }
  17415. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17416. {
  17417. for (int index = 0; index < GB_QUANTITY; index++)
  17418. {
  17419. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17420. {
  17421. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17422. }
  17423. }
  17424. }
  17425. else if(gunType[gun_index] == GUN_TYPE_DO)
  17426. {
  17427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17428. {
  17429. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17430. {
  17431. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17432. }
  17433. }
  17434. }
  17435. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17436. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17437. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17438. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17439. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17440. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17441. } // END FOR DC CASE
  17442. }
  17443. //2.6====================================== Current.Import L2 ==============================================
  17444. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17445. {
  17446. // AC 3 phase L2 current
  17447. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17448. {
  17449. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17450. {
  17451. tempIndex = 2;
  17452. }
  17453. else
  17454. {
  17455. tempIndex = gun_index;
  17456. }
  17457. for (int index = 0; index < AC_QUANTITY; index++)
  17458. {
  17459. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17460. {
  17461. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17462. }
  17463. }// End of for AC_QUANTITY
  17464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17465. }
  17466. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17468. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17470. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17471. }
  17472. //2.7====================================== Current.Import L3 ==============================================
  17473. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17474. {
  17475. // AC 3 phase L3 current
  17476. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17477. {
  17478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17479. {
  17480. tempIndex = 2;
  17481. }
  17482. else
  17483. {
  17484. tempIndex = gun_index;
  17485. }
  17486. for (int index = 0; index < AC_QUANTITY; index++)
  17487. {
  17488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17489. {
  17490. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17491. }
  17492. }// End of for AC_QUANTITY
  17493. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17494. }
  17495. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17499. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17500. }
  17501. //2.9====================================== Voltage L2 ====================================================
  17502. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17503. {
  17504. // AC 3 phase L2 volatge
  17505. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17506. {
  17507. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17508. {
  17509. tempIndex = 2;
  17510. }
  17511. else
  17512. {
  17513. tempIndex = gun_index;
  17514. }
  17515. for (int index = 0; index < AC_QUANTITY; index++)
  17516. {
  17517. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17518. {
  17519. 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
  17520. }
  17521. } // END OF FOR AC_QUANTITY
  17522. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17523. }
  17524. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17525. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17527. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17528. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17529. }
  17530. //2.10====================================== Voltage L3 ====================================================
  17531. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17532. {
  17533. // AC 3 phase L3 volatge
  17534. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17535. {
  17536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17537. {
  17538. tempIndex = 2;
  17539. }
  17540. else
  17541. {
  17542. tempIndex = gun_index;
  17543. }
  17544. for (int index = 0; index < AC_QUANTITY; index++)
  17545. {
  17546. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17547. {
  17548. 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
  17549. }
  17550. } // END OF FOR AC_QUANTITY
  17551. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17552. }
  17553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17555. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17558. }
  17559. //====================== Start SoC ================================
  17560. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17561. {
  17562. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17563. 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))
  17564. {
  17565. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17566. {
  17567. tempIndex = ((gun_index==2) ? 1: 0);
  17568. }
  17569. else
  17570. {
  17571. tempIndex = gun_index;
  17572. }
  17573. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17574. {
  17575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17576. {
  17577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17578. {
  17579. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17580. }
  17581. }
  17582. }
  17583. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17584. {
  17585. for (int index = 0; index < CCS_QUANTITY; index++)
  17586. {
  17587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17588. {
  17589. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17590. }
  17591. }
  17592. }
  17593. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17594. {
  17595. for (int index = 0; index < GB_QUANTITY; index++)
  17596. {
  17597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17598. {
  17599. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17600. }
  17601. }
  17602. }
  17603. else if(gunType[gun_index] == GUN_TYPE_DO)
  17604. {
  17605. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17606. {
  17607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17608. {
  17609. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17610. }
  17611. }
  17612. }
  17613. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17614. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17615. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17616. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17619. } // END FOR DC CASE
  17620. }
  17621. //======================================== Message create ==============================================
  17622. json_object *StopTransaction = json_object_new_object();
  17623. json_object *transactionDatas = json_object_new_array();
  17624. json_object *sampledValues = json_object_new_array();
  17625. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17626. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17627. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17628. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17629. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17630. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17631. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17632. {
  17633. json_object *transactionData = json_object_new_object();
  17634. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17635. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17636. {
  17637. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17638. {
  17639. json_object *sampledValue = json_object_new_object();
  17640. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17641. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17642. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17643. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17644. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17645. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17646. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17647. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17648. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17649. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17650. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17651. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17652. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17653. json_object_array_add(sampledValues, sampledValue);
  17654. }
  17655. }
  17656. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17657. json_object_array_add(transactionDatas, transactionData);
  17658. }
  17659. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17660. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17661. ,MESSAGE_TYPE_CALL
  17662. ,guid
  17663. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17664. json_object_put(StopTransaction);
  17665. // Check File "TempStopTransaction" Exist
  17666. if((access(TempStopTransaction,F_OK))!=-1)
  17667. {
  17668. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17669. fclose(fopen(TempStopTransaction, "w"));
  17670. }
  17671. else
  17672. {
  17673. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17674. FILE *log = fopen(TempStopTransaction, "w+");
  17675. if(log == NULL)
  17676. {
  17677. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17678. return ;
  17679. }
  17680. else
  17681. {
  17682. fclose(log);
  17683. }
  17684. }
  17685. //Add TempStopTransaction | Update TempStopTransaction
  17686. // open file for writing
  17687. FILE *outfile;
  17688. outfile = fopen (TempStopTransaction, "a");
  17689. //DEBUG_INFO("data = %s\n", queuedata);
  17690. fputs(queuedata, outfile);
  17691. fputs("\n", outfile);
  17692. fclose (outfile);
  17693. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17694. }
  17695. void checkTempStopTransaction(int gun_index)
  17696. {
  17697. FILE *fptr1;
  17698. char ch;
  17699. char str[QUEUE_MESSAGE_LENGTH]={0};
  17700. char guid[37]={0};
  17701. char tempdata[65]={0};
  17702. char connectorStr[2]={0};
  17703. char TempStopTransaction[256];
  17704. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17705. fptr1 = fopen(TempStopTransaction, "r");
  17706. //TempStopTransaction格式: 槍號,StopTransaction封包
  17707. if (!fptr1)
  17708. {
  17709. //printf(" File not found or unable to open the input file!!\n");
  17710. return ;
  17711. }
  17712. ch=fgetc(fptr1);
  17713. //printf(" Now the content of the file %s is : \n",fname);
  17714. rewind(fptr1);
  17715. if(ch!=EOF)
  17716. {
  17717. // copy all contents to the temporary file except the specific line
  17718. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17719. {
  17720. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17721. if(str[0]=='\0')
  17722. {
  17723. break;
  17724. }
  17725. //TempStopTransaction格式: 槍號,StopTransaction封包
  17726. strncpy(connectorStr, str, 1);
  17727. if(atoi(connectorStr) != (gun_index+1))
  17728. {
  17729. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17730. fclose(fptr1);
  17731. return ;
  17732. }
  17733. //random_uuid(guid);
  17734. strncpy(guid, str+6, 36); //copy guid
  17735. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17736. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17737. {
  17738. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17739. }
  17740. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17741. OCPP_insert_transaction_msg(NO, str);
  17742. memset(str,0,ARRAY_SIZE(str));
  17743. }
  17744. }
  17745. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17746. fclose(fptr1);
  17747. remove(TempStopTransaction); // remove the original file
  17748. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17749. }
  17750. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17751. {
  17752. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17753. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17754. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17755. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17756. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17757. }
  17758. int GetWebSocketPingInterval(void)
  17759. {
  17760. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17761. }
  17762. int GetServerSign(void)
  17763. {
  17764. return server_sign;
  17765. }
  17766. uint8_t GetOcppSecurityProfile()
  17767. {
  17768. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17769. }
  17770. void GetOcppChargerBoxId(uint8_t *data)
  17771. {
  17772. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17773. }
  17774. void GetOcppSecurityPassword(uint8_t *data)
  17775. {
  17776. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17777. }
  17778. void SetOcppVersion(uint8_t *version)
  17779. {
  17780. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17781. DEBUG_INFO("ocpp version: %s\n", version);
  17782. if(strstr((char*)version, "ocpp1.6") != NULL)
  17783. {
  17784. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17785. }
  17786. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17787. {
  17788. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17789. system("pkill OcppBackend");
  17790. }
  17791. }
  17792. void SetServerSign(int value)
  17793. {
  17794. server_sign = value;
  17795. }
  17796. int GetBootNotificationInterval(void)
  17797. {
  17798. return BootNotificationInterval;
  17799. }
  17800. int GetInternetConn(void)
  17801. {
  17802. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17803. }
  17804. int GetBackendConnectionTimeout(void)
  17805. {
  17806. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17807. }
  17808. int isConnectorInitMode(int gun_index)
  17809. {
  17810. int tempIndex = 0;
  17811. int result = TRUE;
  17812. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17813. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17814. {
  17815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17816. {
  17817. tempIndex = ((gun_index==2) ? 1: 0);
  17818. }
  17819. else
  17820. {
  17821. tempIndex = gun_index;
  17822. }
  17823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17824. {
  17825. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17826. {
  17827. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17828. } //end of the same index
  17829. }//end of for CHAdeMO_QUANTITY
  17830. }
  17831. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17832. {
  17833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17834. {
  17835. tempIndex = ((gun_index==2) ? 1: 0);
  17836. }
  17837. else
  17838. {
  17839. tempIndex = gun_index;
  17840. }
  17841. for (int index = 0; index < CCS_QUANTITY; index++)
  17842. {
  17843. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17844. {
  17845. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17846. } //end of the same index
  17847. } // end of for CCS_QUANTITY
  17848. }
  17849. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17850. {
  17851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17852. {
  17853. tempIndex = ((gun_index==2) ? 1: 0);
  17854. }
  17855. else
  17856. {
  17857. tempIndex = gun_index;
  17858. }
  17859. for (int index = 0; index < GB_QUANTITY; index++)
  17860. {
  17861. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17862. {
  17863. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17864. } //end of the same index
  17865. } // end of for GB_QUANTITY
  17866. }
  17867. else if(gunType[gun_index] == GUN_TYPE_DO)
  17868. {
  17869. tempIndex = gun_index;
  17870. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17871. {
  17872. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17873. {
  17874. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17875. } //end of the same index
  17876. }
  17877. }
  17878. else
  17879. {
  17880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17881. {
  17882. tempIndex = 2;
  17883. }
  17884. else
  17885. {
  17886. tempIndex = gun_index;
  17887. }
  17888. for (int index = 0; index < AC_QUANTITY; index++)
  17889. {
  17890. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17891. {
  17892. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17893. }//end of the same index
  17894. }//end of for AC_QUANTITY
  17895. }
  17896. return result;
  17897. }
  17898. void refreshProcDogTimer()
  17899. {
  17900. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17901. }
  17902. void InitialSystemValue(void)
  17903. {
  17904. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17905. locallistVersion=0;
  17906. BootNotificationInterval = 0;
  17907. authorizeRetryTimes = 0;
  17908. GunStatusInterval = 10;
  17909. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17910. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17911. //Hear Beat
  17912. HeartBeatWithNOResponse = 0;
  17913. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17914. FirstHeartBeat = 0;
  17915. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17916. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17917. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17918. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17919. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17920. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17921. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17922. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17923. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17924. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17925. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17926. //Status && ConnectorPlugIn Setting
  17927. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17928. {
  17929. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17930. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17931. }
  17932. for (int index = 0; index < CCS_QUANTITY; index++)
  17933. {
  17934. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17935. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17936. }
  17937. for (int index = 0; index < GB_QUANTITY; index++)
  17938. {
  17939. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17940. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17941. }
  17942. for (int index = 0; index < AC_QUANTITY; index++)
  17943. {
  17944. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17945. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17946. }
  17947. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17948. {
  17949. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17950. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17951. }
  17952. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17953. {
  17954. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17955. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17956. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17957. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17958. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17959. }
  17960. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17961. refreshStartTimer(&clientTime.Heartbeat);
  17962. sleep(1);
  17963. }
  17964. void LWS_Send(char *str)
  17965. {
  17966. //=====================================================
  17967. // Check InternetConn 0: disconnected, 1: connected
  17968. //====================================================
  17969. if(GetOcppConnStatus() == 0)
  17970. {
  17971. DEBUG_INFO("offline now !!!\n");
  17972. return;
  17973. }
  17974. // Only disable isWebsocketSendable operation initiated by charger
  17975. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17976. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17977. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17978. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17979. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17980. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17981. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17982. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17983. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17984. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17985. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17986. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17987. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17988. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17989. {
  17990. isWebsocketSendable = 0;
  17991. }
  17992. pthread_mutex_lock(&lock_send);
  17993. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17994. sprintf((char *)SendBuffer, "%s", str);
  17995. SendBufLen = strlen(str);
  17996. pthread_mutex_unlock(&lock_send);
  17997. lws_callback_on_writable(wsi_client);
  17998. //lws_service(context, 0);
  17999. //sleep(1);
  18000. }
  18001. void LWS_SendNow(char *str)
  18002. {
  18003. //=====================================================
  18004. // Check InternetConn 0: disconnected, 1: connected
  18005. //====================================================
  18006. if(GetOcppConnStatus() == 0)
  18007. {
  18008. DEBUG_INFO("offline now !!!\n");
  18009. return;
  18010. }
  18011. // Only disable isWebsocketSendable operation initiated by charger
  18012. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18013. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18014. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18015. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18016. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18017. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18018. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18019. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18020. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18021. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18022. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18023. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18024. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18025. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18026. {
  18027. isWebsocketSendable = 0;
  18028. }
  18029. pthread_mutex_lock(&lock_send);
  18030. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18031. sprintf((char *)SendBuffer, "%s", str);
  18032. SendBufLen = strlen(str);
  18033. pthread_mutex_unlock(&lock_send);
  18034. lws_callback_on_writable(wsi_client);
  18035. lws_service(context, 0);
  18036. //sleep(1);
  18037. }