MessageHandler.c 915 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704
  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((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. if(dataType == ReadingContext_Sample_Clock)
  5950. {
  5951. struct tm *tmTarget;
  5952. struct timeb tbTarget;
  5953. tbTarget.time = mktime(tm);
  5954. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  5955. tmTarget = gmtime(&tbTarget.time);
  5956. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  5957. }
  5958. else
  5959. {
  5960. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5961. }
  5962. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5963. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5964. //********************************(1)Current.Import L1************************************************/
  5965. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5966. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5967. (dataType == ReadingContext_Trigger))
  5968. {
  5969. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5971. {
  5972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5973. {
  5974. tempIndex = ((gun_index==2) ? 1: 0);
  5975. }
  5976. else
  5977. {
  5978. tempIndex = gun_index;
  5979. }
  5980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5981. {
  5982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5983. {
  5984. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5985. }
  5986. }
  5987. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5988. }
  5989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5990. {
  5991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5992. {
  5993. tempIndex = ((gun_index==2) ? 1: 0);
  5994. }
  5995. else
  5996. {
  5997. tempIndex = gun_index;
  5998. }
  5999. for (int index = 0; index < CCS_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6002. {
  6003. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6004. }
  6005. }
  6006. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6007. }
  6008. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6009. {
  6010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6011. {
  6012. tempIndex = ((gun_index==2) ? 1: 0);
  6013. }
  6014. else
  6015. {
  6016. tempIndex = gun_index;
  6017. }
  6018. for (int index = 0; index < GB_QUANTITY; index++)
  6019. {
  6020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6021. {
  6022. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6023. }
  6024. }
  6025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6026. }
  6027. else if(gunType[gun_index] == GUN_TYPE_DO)
  6028. {
  6029. tempIndex = gun_index;
  6030. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6031. {
  6032. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6033. {
  6034. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6035. }
  6036. }
  6037. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6038. }
  6039. else
  6040. {
  6041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6042. {
  6043. tempIndex = 2;
  6044. }
  6045. else
  6046. {
  6047. tempIndex = gun_index;
  6048. }
  6049. for (int index = 0; index < AC_QUANTITY; index++)
  6050. {
  6051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6052. {
  6053. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6054. }
  6055. }
  6056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6057. }
  6058. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6059. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6060. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6061. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6062. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6063. }
  6064. //********************************(2)Energy.Active.Import.Register ************************************************/
  6065. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6066. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6067. (dataType == ReadingContext_Trigger))
  6068. {
  6069. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6070. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6071. {
  6072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6073. {
  6074. tempIndex = ((gun_index==2) ? 1: 0);
  6075. }
  6076. else
  6077. {
  6078. tempIndex = gun_index;
  6079. }
  6080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6085. }
  6086. }
  6087. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6088. }
  6089. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6090. {
  6091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6092. {
  6093. tempIndex = ((gun_index==2) ? 1: 0);
  6094. }
  6095. else
  6096. {
  6097. tempIndex = gun_index;
  6098. }
  6099. for (int index = 0; index < CCS_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6104. }
  6105. }
  6106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6107. }
  6108. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6109. {
  6110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6111. {
  6112. tempIndex = ((gun_index==2) ? 1: 0);
  6113. }
  6114. else
  6115. {
  6116. tempIndex = gun_index;
  6117. }
  6118. for (int index = 0; index < GB_QUANTITY; index++)
  6119. {
  6120. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6121. {
  6122. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6123. }
  6124. }
  6125. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6126. }
  6127. else if(gunType[gun_index] == GUN_TYPE_DO)
  6128. {
  6129. tempIndex = gun_index;
  6130. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6133. {
  6134. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6135. }
  6136. }
  6137. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6138. }
  6139. else
  6140. {
  6141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6142. {
  6143. tempIndex = 2;
  6144. }
  6145. else
  6146. {
  6147. tempIndex = gun_index;
  6148. }
  6149. for (int index = 0; index < AC_QUANTITY; index++)
  6150. {
  6151. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6152. {
  6153. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6154. }
  6155. }
  6156. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6157. }
  6158. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6159. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6160. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6161. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6162. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6163. }
  6164. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6165. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6166. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6167. (dataType == ReadingContext_Trigger))
  6168. {
  6169. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6170. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6171. {
  6172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6173. {
  6174. tempIndex = ((gun_index==2) ? 1: 0);
  6175. }
  6176. else
  6177. {
  6178. tempIndex = gun_index;
  6179. }
  6180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6181. {
  6182. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6183. {
  6184. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6185. }
  6186. } // END OF FOR CHAdeMO_QUANTITY
  6187. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6188. }
  6189. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6190. {
  6191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6192. {
  6193. tempIndex = ((gun_index==2) ? 1: 0);
  6194. }
  6195. else
  6196. {
  6197. tempIndex = gun_index;
  6198. }
  6199. for (int index = 0; index < CCS_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6202. {
  6203. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6204. }
  6205. } // END OF CCS_QUANTITY
  6206. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6207. }
  6208. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6209. {
  6210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6211. {
  6212. tempIndex = ((gun_index==2) ? 1: 0);
  6213. }
  6214. else
  6215. {
  6216. tempIndex = gun_index;
  6217. }
  6218. for (int index = 0; index < GB_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6221. {
  6222. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6223. }
  6224. } // END OF GB_QUANTITY
  6225. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6226. }
  6227. else if(gunType[gun_index] == GUN_TYPE_DO)
  6228. {
  6229. tempIndex = gun_index;
  6230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6231. {
  6232. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6233. {
  6234. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6235. }
  6236. }
  6237. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6238. }
  6239. else
  6240. {
  6241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6242. {
  6243. tempIndex = 2;
  6244. }
  6245. else
  6246. {
  6247. tempIndex = gun_index;
  6248. }
  6249. for (int index = 0; index < AC_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6252. {
  6253. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6254. }
  6255. }
  6256. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6257. }
  6258. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6259. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6260. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6261. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6262. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6263. }
  6264. //********************************(4)Power.Active.Import************************************************/
  6265. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6266. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6267. (dataType == ReadingContext_Trigger))
  6268. {
  6269. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6270. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6271. {
  6272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6273. {
  6274. tempIndex = ((gun_index==2) ? 1: 0);
  6275. }
  6276. else
  6277. {
  6278. tempIndex = gun_index;
  6279. }
  6280. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6281. {
  6282. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6283. {
  6284. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6285. }
  6286. } // END OF FOR
  6287. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6288. }
  6289. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6290. {
  6291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6292. {
  6293. tempIndex = ((gun_index==2) ? 1: 0);
  6294. }
  6295. else
  6296. {
  6297. tempIndex = gun_index;
  6298. }
  6299. for (int index = 0; index < CCS_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6302. {
  6303. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6304. }
  6305. }
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6307. }
  6308. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6309. {
  6310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6311. {
  6312. tempIndex = ((gun_index==2) ? 1: 0);
  6313. }
  6314. else
  6315. {
  6316. tempIndex = gun_index;
  6317. }
  6318. for (int index = 0; index < GB_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6321. {
  6322. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6323. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6324. }
  6325. }
  6326. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6327. }
  6328. else if(gunType[gun_index] == GUN_TYPE_DO)
  6329. {
  6330. tempIndex = gun_index;
  6331. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6332. {
  6333. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6334. {
  6335. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6336. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6337. }
  6338. }
  6339. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6340. }
  6341. else
  6342. {
  6343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6344. {
  6345. tempIndex = 2;
  6346. }
  6347. else
  6348. {
  6349. tempIndex = gun_index;
  6350. }
  6351. for (int index = 0; index < AC_QUANTITY; index++)
  6352. {
  6353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6354. {
  6355. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6356. }
  6357. }
  6358. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6359. }
  6360. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6361. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6362. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6363. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6364. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6365. }
  6366. //***********************************************(5)VOLTAGE L1******************************************************/
  6367. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6368. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6369. (dataType == ReadingContext_Trigger))
  6370. {
  6371. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6372. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6373. {
  6374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6375. {
  6376. tempIndex = ((gun_index==2) ? 1: 0);
  6377. }
  6378. else
  6379. {
  6380. tempIndex = gun_index;
  6381. }
  6382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6383. {
  6384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6385. {
  6386. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6387. }
  6388. }
  6389. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6390. }
  6391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6392. {
  6393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6394. {
  6395. tempIndex = ((gun_index==2) ? 1: 0);
  6396. }
  6397. else
  6398. {
  6399. tempIndex = gun_index;
  6400. }
  6401. for (int index = 0; index < CCS_QUANTITY; index++)
  6402. {
  6403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6404. {
  6405. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6406. }
  6407. }
  6408. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6409. }
  6410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6411. {
  6412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6413. {
  6414. tempIndex = ((gun_index==2) ? 1: 0);
  6415. }
  6416. else
  6417. {
  6418. tempIndex = gun_index;
  6419. }
  6420. for (int index = 0; index < GB_QUANTITY; index++)
  6421. {
  6422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6423. {
  6424. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6425. }
  6426. }
  6427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6428. }
  6429. else if(gunType[gun_index] == GUN_TYPE_DO)
  6430. {
  6431. tempIndex = gun_index;
  6432. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6433. {
  6434. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6435. {
  6436. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6437. }
  6438. }
  6439. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6440. }
  6441. else
  6442. {
  6443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6444. {
  6445. tempIndex = 2;
  6446. }
  6447. else
  6448. {
  6449. tempIndex = gun_index;
  6450. }
  6451. for (int index = 0; index < AC_QUANTITY; index++)
  6452. {
  6453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6454. {
  6455. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6456. }
  6457. }
  6458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6459. }
  6460. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6461. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6462. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6463. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6464. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6465. }
  6466. //***********************************************(6)SOC******************************************************/
  6467. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6468. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6469. (dataType == ReadingContext_Trigger))
  6470. {
  6471. 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))
  6472. {
  6473. //idx_sample=5;
  6474. //sampledValue = NULL;
  6475. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6476. {
  6477. tempIndex = ((gun_index==2) ? 1: 0);
  6478. }
  6479. else
  6480. {
  6481. tempIndex = gun_index;
  6482. }
  6483. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6484. {
  6485. //tempIndex = ((gun_index==2) ? 1: 0);
  6486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6487. {
  6488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6489. {
  6490. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6491. }
  6492. }
  6493. }
  6494. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6495. {
  6496. //tempIndex = ((gun_index==2) ? 1: 0);
  6497. for (int index = 0; index < CCS_QUANTITY; index++)
  6498. {
  6499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6500. {
  6501. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6502. }
  6503. }
  6504. }
  6505. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6506. {
  6507. //tempIndex = ((gun_index==2) ? 1: 0);
  6508. for (int index = 0; index < GB_QUANTITY; index++)
  6509. {
  6510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6511. {
  6512. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6513. }
  6514. }
  6515. }
  6516. else if(gunType[gun_index] == GUN_TYPE_DO)
  6517. {
  6518. //tempIndex = ((gun_index==2) ? 1: 0);
  6519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6520. {
  6521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6522. {
  6523. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6524. }
  6525. }
  6526. }
  6527. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6528. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6529. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6531. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6533. }
  6534. }
  6535. //********************************(7)Current.Import L2************************************************/
  6536. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6537. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6538. (dataType == ReadingContext_Trigger))
  6539. {
  6540. // Only for AC 3 phase
  6541. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6542. {
  6543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6544. {
  6545. tempIndex = 2;
  6546. }
  6547. else
  6548. {
  6549. tempIndex = gun_index;
  6550. }
  6551. for (int index = 0; index < AC_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6554. {
  6555. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6556. }
  6557. }
  6558. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6559. }
  6560. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6562. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6563. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6564. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6565. }
  6566. //********************************(8)Current.Import L3************************************************/
  6567. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6568. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6569. (dataType == ReadingContext_Trigger))
  6570. {
  6571. // Only for AC 3 phase
  6572. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6573. {
  6574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6575. {
  6576. tempIndex = 2;
  6577. }
  6578. else
  6579. {
  6580. tempIndex = gun_index;
  6581. }
  6582. for (int index = 0; index < AC_QUANTITY; index++)
  6583. {
  6584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6585. {
  6586. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6587. }
  6588. }
  6589. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6590. }
  6591. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6592. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6593. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6594. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6596. }
  6597. //***********************************************(9)VOLTAGE L2******************************************************/
  6598. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6599. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6600. (dataType == ReadingContext_Trigger))
  6601. {
  6602. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6603. {
  6604. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6605. {
  6606. tempIndex = 2;
  6607. }
  6608. else
  6609. {
  6610. tempIndex = gun_index;
  6611. }
  6612. for (int index = 0; index < AC_QUANTITY; index++)
  6613. {
  6614. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6615. {
  6616. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6617. }
  6618. }
  6619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6620. }
  6621. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6622. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6623. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6624. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6625. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6626. }
  6627. //***********************************************(10)VOLTAGE L3******************************************************/
  6628. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6629. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6630. (dataType == ReadingContext_Trigger))
  6631. {
  6632. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6633. {
  6634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6635. {
  6636. tempIndex = 2;
  6637. }
  6638. else
  6639. {
  6640. tempIndex = gun_index;
  6641. }
  6642. for (int index = 0; index < AC_QUANTITY; index++)
  6643. {
  6644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6645. {
  6646. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6647. }
  6648. }
  6649. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6650. }
  6651. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6652. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6653. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6654. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6655. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6656. }
  6657. //***********************************************(11)Current.Offered******************************************************/
  6658. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6659. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6660. (dataType == ReadingContext_Trigger))
  6661. {
  6662. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6663. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6664. {
  6665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6666. {
  6667. tempIndex = ((gun_index==2) ? 1: 0);
  6668. }
  6669. else
  6670. {
  6671. tempIndex = gun_index;
  6672. }
  6673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6674. {
  6675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6676. {
  6677. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6678. }
  6679. } // END OF FOR CHAdeMO_QUANTITY
  6680. }
  6681. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6682. {
  6683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6684. {
  6685. tempIndex = ((gun_index==2) ? 1: 0);
  6686. }
  6687. else
  6688. {
  6689. tempIndex = gun_index;
  6690. }
  6691. for (int index = 0; index < CCS_QUANTITY; index++)
  6692. {
  6693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6694. {
  6695. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6696. }
  6697. } // END OF CCS_QUANTITY
  6698. }
  6699. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6700. {
  6701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6702. {
  6703. tempIndex = ((gun_index==2) ? 1: 0);
  6704. }
  6705. else
  6706. {
  6707. tempIndex = gun_index;
  6708. }
  6709. for (int index = 0; index < GB_QUANTITY; index++)
  6710. {
  6711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6712. {
  6713. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6714. }
  6715. } // END OF GB_QUANTITY
  6716. }
  6717. else if(gunType[gun_index] == GUN_TYPE_DO)
  6718. {
  6719. tempIndex = gun_index;
  6720. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6721. {
  6722. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6723. {
  6724. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6725. }
  6726. }
  6727. }
  6728. else
  6729. {
  6730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6731. {
  6732. tempIndex = 2;
  6733. }
  6734. else
  6735. {
  6736. tempIndex = gun_index;
  6737. }
  6738. for (int index = 0; index < AC_QUANTITY; index++)
  6739. {
  6740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6741. {
  6742. uint16_t currentOffer;
  6743. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6744. {
  6745. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6746. }
  6747. else
  6748. {
  6749. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6750. }
  6751. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6752. }
  6753. }
  6754. }
  6755. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6756. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6757. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6758. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6759. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6760. }
  6761. //***********************************************(12)Power.Offered******************************************************/
  6762. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6763. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6764. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6765. {
  6766. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6767. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6768. {
  6769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6770. {
  6771. tempIndex = ((gun_index==2) ? 1: 0);
  6772. }
  6773. else
  6774. {
  6775. tempIndex = gun_index;
  6776. }
  6777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6778. {
  6779. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6780. {
  6781. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6782. }
  6783. } // END OF FOR CHAdeMO_QUANTITY
  6784. }
  6785. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6786. {
  6787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6788. {
  6789. tempIndex = ((gun_index==2) ? 1: 0);
  6790. }
  6791. else
  6792. {
  6793. tempIndex = gun_index;
  6794. }
  6795. for (int index = 0; index < CCS_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6798. {
  6799. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6800. }
  6801. } // END OF CCS_QUANTITY
  6802. }
  6803. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6804. {
  6805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6806. {
  6807. tempIndex = ((gun_index==2) ? 1: 0);
  6808. }
  6809. else
  6810. {
  6811. tempIndex = gun_index;
  6812. }
  6813. for (int index = 0; index < GB_QUANTITY; index++)
  6814. {
  6815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6816. {
  6817. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6818. }
  6819. } // END OF GB_QUANTITY
  6820. }
  6821. else if(gunType[gun_index] == GUN_TYPE_DO)
  6822. {
  6823. tempIndex = gun_index;
  6824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6825. {
  6826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6827. {
  6828. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6829. }
  6830. }
  6831. }
  6832. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6833. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6834. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6835. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6836. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6837. }
  6838. // Message create ====================================================================================================
  6839. if(TRUE)
  6840. {
  6841. json_object *MeterValueReq = json_object_new_object();
  6842. json_object *MeterValues = json_object_new_array();
  6843. json_object *sampledValues = json_object_new_array();
  6844. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6845. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6846. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6847. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6848. {
  6849. json_object *MeterValue = json_object_new_object();
  6850. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6851. {
  6852. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6853. {
  6854. json_object *sampledValue = json_object_new_object();
  6855. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6856. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6857. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6858. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6859. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6860. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6861. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6862. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6863. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6864. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6865. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6866. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6867. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6868. json_object_array_add(sampledValues, sampledValue);
  6869. }
  6870. }
  6871. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6872. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6873. json_object_array_add(MeterValues, MeterValue);
  6874. }
  6875. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6876. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6877. ,gun_index + 1
  6878. ,MESSAGE_TYPE_CALL
  6879. ,guid
  6880. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6881. json_object_put(MeterValueReq);
  6882. }
  6883. // Put request guid to hash map
  6884. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6885. 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*/)
  6886. {
  6887. result = PASS;
  6888. //DEBUG_INFO("MeterValues mapitem pass\n");
  6889. }
  6890. if((dataType != ReadingContext_Trigger) &&
  6891. (dataType != ReadingContext_Sample_Clock) &&
  6892. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6893. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6894. else
  6895. {
  6896. if(FirstHeartBeat)
  6897. LWS_Send(queuedata +2);
  6898. }
  6899. return result;
  6900. }
  6901. int sendLogStatusNotificationRequest(char *status)
  6902. {
  6903. mtrace();
  6904. int result = PASS;
  6905. char message[4096]={0};
  6906. char guid[37]={0};
  6907. char tempdata[128]={0};
  6908. json_object *LogStatusNotification = json_object_new_object();
  6909. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6910. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6911. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6912. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6913. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6914. random_uuid(guid);
  6915. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6916. json_object_put(LogStatusNotification);
  6917. LWS_Send(message);
  6918. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6919. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6920. {
  6921. result = PASS;
  6922. }
  6923. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6924. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6925. return result;
  6926. }
  6927. int sendSecurityEventNotificationRequest()
  6928. {
  6929. mtrace();
  6930. int result = PASS;
  6931. char message[4096]={0};
  6932. char guid[37]={0};
  6933. char tempdata[128]={0};
  6934. json_object *SecurityEventNotification = json_object_new_object();
  6935. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6936. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6937. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6938. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6939. random_uuid(guid);
  6940. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6941. json_object_put(SecurityEventNotification);
  6942. LWS_Send(message);
  6943. sprintf(tempdata, "SecurityEventNotification,0");
  6944. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6945. {
  6946. result = PASS;
  6947. }
  6948. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6949. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6950. return result;
  6951. }
  6952. int sendSignCertificateRequest()
  6953. {
  6954. mtrace();
  6955. int result = PASS;
  6956. char message[4096]={0};
  6957. char guid[37]={0};
  6958. char tempdata[128]={0};
  6959. json_object *SignCertificate = json_object_new_object();
  6960. DEBUG_INFO("sendSignCertificateRequest...\n");
  6961. // Read csr file content
  6962. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6963. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6964. char *line = NULL;
  6965. size_t len = 0;
  6966. while(getline(&line, &len, fp) != -1)
  6967. {
  6968. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6969. {
  6970. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6971. }
  6972. }
  6973. fclose(fp);
  6974. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6975. random_uuid(guid);
  6976. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6977. json_object_put(SignCertificate);
  6978. LWS_Send(message);
  6979. sprintf(tempdata, "SignCertificate,0");
  6980. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6981. {
  6982. result = PASS;
  6983. }
  6984. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6985. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6986. return result;
  6987. }
  6988. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6989. {
  6990. mtrace();
  6991. int result = PASS;
  6992. char message[110]={0};
  6993. char guid[37]={0};
  6994. char tempdata[65]={0};
  6995. json_object *FirmwareStatusNotification = json_object_new_object();
  6996. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6997. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6998. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6999. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7000. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7001. random_uuid(guid);
  7002. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7003. json_object_put(FirmwareStatusNotification);
  7004. LWS_Send(message);
  7005. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7006. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7007. {
  7008. result = PASS;
  7009. }
  7010. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7011. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7012. return result;
  7013. }
  7014. //==========================================
  7015. // send confirm routine
  7016. //==========================================
  7017. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7018. {
  7019. mtrace();
  7020. int result = FAIL;
  7021. char message[100]={0};
  7022. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7023. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7024. LWS_Send(message);
  7025. result = TRUE;
  7026. return result;
  7027. }
  7028. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7029. {
  7030. mtrace();
  7031. int result = FAIL;
  7032. char message[100]={0};
  7033. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7034. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7035. LWS_Send(message);
  7036. result = TRUE;
  7037. return result;
  7038. }
  7039. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7040. {
  7041. mtrace();
  7042. int result = FAIL;
  7043. char message[100]={0};
  7044. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7045. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7046. LWS_Send(message);
  7047. result = TRUE;
  7048. return result;
  7049. }
  7050. int sendClearCacheConfirmation(char *uuid,char *payload)
  7051. {
  7052. mtrace();
  7053. int result = FAIL;
  7054. char message[500]={0};
  7055. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7056. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7057. LWS_Send(message);
  7058. return result;
  7059. }
  7060. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7061. {
  7062. mtrace();
  7063. int result = FAIL;
  7064. char message[500]={0};
  7065. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7066. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7067. LWS_Send(message);
  7068. return result;
  7069. }
  7070. int sendDataTransferConfirmation(char *uuid,char *payload)
  7071. {
  7072. mtrace();
  7073. char statusStr[20]={0};
  7074. char dataStr[10]={0};
  7075. char sstr[20]={0};
  7076. int c = 0;
  7077. char *loc;
  7078. int result = FAIL;
  7079. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7080. /**********************status**************************/
  7081. loc = strstr(payload, "status");
  7082. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7083. c = 0;
  7084. while (loc[3+strlen("status")+c] != '\"')
  7085. {
  7086. sstr[c] = loc[3+strlen("status")+c];
  7087. c++;
  7088. }
  7089. sstr[c] = '\0';
  7090. strcpy(statusStr, sstr);
  7091. /**********************data**************************/
  7092. loc = strstr(payload, "data");
  7093. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7094. c = 0;
  7095. while (loc[3+strlen("data")+c] != '\"')
  7096. {
  7097. sstr[c] = loc[3+strlen("data")+c];
  7098. c++;
  7099. }
  7100. sstr[c] = '\0';
  7101. strcpy(dataStr, sstr);
  7102. return result;
  7103. }
  7104. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7105. {
  7106. mtrace();
  7107. int result = FAIL;
  7108. char message[1000]={0};
  7109. int CompositeScheduleIndex = 0;
  7110. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7111. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7112. if(nPeriod == 0)
  7113. {
  7114. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7115. {
  7116. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7117. ,MESSAGE_TYPE_CALLRESULT
  7118. ,uuid
  7119. ,payload
  7120. ,connectorIdInt);
  7121. }
  7122. else
  7123. {
  7124. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7125. ,MESSAGE_TYPE_CALLRESULT
  7126. ,uuid
  7127. ,payload
  7128. ,connectorIdInt
  7129. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7130. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7131. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7132. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7133. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7134. }
  7135. }
  7136. else
  7137. {
  7138. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7139. ,MESSAGE_TYPE_CALLRESULT
  7140. ,uuid
  7141. ,payload
  7142. ,connectorIdInt
  7143. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7144. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7145. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7146. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7147. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7148. {
  7149. if (idx_sample == 0)
  7150. {
  7151. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7152. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7153. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7154. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7155. }
  7156. else
  7157. {
  7158. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7159. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7160. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7161. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7162. }
  7163. }
  7164. sprintf(message + strlen(message), "]}}]");
  7165. }
  7166. LWS_Send(message);
  7167. result = TRUE;
  7168. return result;
  7169. }
  7170. int sendGetConfigurationConfirmation(char *uuid)
  7171. {
  7172. mtrace();
  7173. int result = FAIL;
  7174. int MaxKeySupported = 0;
  7175. int sentConfigurationNumber= 0;
  7176. int sentunConfigurationNumber= 0;
  7177. char message[1024*10]={0};
  7178. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7179. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7180. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7181. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7182. ,MESSAGE_TYPE_CALLRESULT
  7183. ,uuid );
  7184. //configuration key
  7185. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7186. {
  7187. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7188. {
  7189. if (sentConfigurationNumber == 0)
  7190. {
  7191. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7192. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7193. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7194. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7195. }
  7196. else
  7197. {
  7198. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7199. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7200. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7201. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7202. }
  7203. sentConfigurationNumber = sentConfigurationNumber + 1;
  7204. }
  7205. }
  7206. sprintf(message + strlen(message), "]");
  7207. if(UnknownKeynum != 0)
  7208. {
  7209. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7210. //unkown key
  7211. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7212. {
  7213. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7214. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7215. if(sentunConfigurationNumber == 0)
  7216. {
  7217. sprintf(message + strlen(message), "\"%s\""
  7218. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7219. }
  7220. else
  7221. {
  7222. sprintf(message + strlen(message), ",\"%s\""
  7223. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7224. }
  7225. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7226. }
  7227. sprintf(message + strlen(message), "]");
  7228. }
  7229. sprintf(message + strlen(message), "}]");
  7230. LWS_Send(message);
  7231. return result;
  7232. }
  7233. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7234. {
  7235. mtrace();
  7236. int result = FAIL;
  7237. char message[400]={0};
  7238. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7239. if(strcmp(payload,"")==0)
  7240. {
  7241. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7242. }
  7243. else
  7244. {
  7245. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7246. }
  7247. LWS_Send(message);
  7248. result = TRUE;
  7249. return result;
  7250. }
  7251. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7252. {
  7253. mtrace();
  7254. int result = FAIL;
  7255. char message[80]={0};
  7256. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7257. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7258. LWS_Send(message);
  7259. result = TRUE;
  7260. return result;
  7261. }
  7262. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7263. {
  7264. mtrace();
  7265. int result = FAIL;
  7266. char message[80]={0};
  7267. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7268. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7269. LWS_Send(message);
  7270. result = TRUE;
  7271. return result;
  7272. }
  7273. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7274. {
  7275. mtrace();
  7276. int result = FAIL;
  7277. char message[80]={0};
  7278. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\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 sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7285. {
  7286. mtrace();
  7287. int result = FAIL;
  7288. char message[80]={0};
  7289. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7290. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7291. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7292. LWS_Send(message);
  7293. result = TRUE;
  7294. return result;
  7295. }
  7296. int sendResetConfirmation(char *uuid,char *payload)
  7297. {
  7298. mtrace();
  7299. int result = FAIL;
  7300. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7301. char message[80]={0};
  7302. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7303. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7304. LWS_Send(message);
  7305. result = TRUE;
  7306. return result;
  7307. }
  7308. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7309. {
  7310. mtrace();
  7311. int result = FAIL;
  7312. char message[500]={0};
  7313. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7314. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7315. LWS_Send(message);
  7316. result = TRUE;
  7317. return result;
  7318. }
  7319. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7320. {
  7321. mtrace();
  7322. int result = FAIL;
  7323. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7324. char message[80]={0};
  7325. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7326. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7327. LWS_Send(message);
  7328. result = TRUE;
  7329. return result;
  7330. }
  7331. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7332. {
  7333. mtrace();
  7334. int result = FAIL;
  7335. char message[80]={0};
  7336. DEBUG_INFO("sendTriggerMessageConfirmation...\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 sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7343. {
  7344. mtrace();
  7345. int result = FAIL;
  7346. char message[80]={0};
  7347. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7348. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7349. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7350. LWS_Send(message);
  7351. result = TRUE;
  7352. return result;
  7353. }
  7354. int sendUpdateFirmwareConfirmation(char *uuid)
  7355. {
  7356. mtrace();
  7357. int result = FAIL;
  7358. char message[60]={0};
  7359. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7360. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7361. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7362. LWS_Send(message);
  7363. result = TRUE;
  7364. return result;
  7365. }
  7366. int sendCertificateSignedConfirmation(char *uuid)
  7367. {
  7368. mtrace();
  7369. int result = PASS;
  7370. char message[4096]={0};
  7371. json_object *CertificateSigned = json_object_new_object();
  7372. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7373. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7374. sprintf(message,"[%d,\"%s\",%s]"
  7375. ,MESSAGE_TYPE_CALLRESULT
  7376. ,uuid
  7377. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7378. json_object_put(CertificateSigned);
  7379. LWS_Send(message);
  7380. return result;
  7381. }
  7382. int sendDeleteCertificateConfirmation(char *uuid)
  7383. {
  7384. mtrace();
  7385. int result = PASS;
  7386. char message[4096]={0};
  7387. json_object *DeleteCertificate = json_object_new_object();
  7388. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7389. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7390. sprintf(message,"[%d,\"%s\",%s]"
  7391. ,MESSAGE_TYPE_CALLRESULT
  7392. ,uuid
  7393. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7394. json_object_put(DeleteCertificate);
  7395. LWS_Send(message);
  7396. return result;
  7397. }
  7398. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7399. {
  7400. mtrace();
  7401. int result = PASS;
  7402. char message[4096]={0};
  7403. json_object *ExtendedTriggerMessage = json_object_new_object();
  7404. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7405. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7406. sprintf(message,"[%d,\"%s\",%s]"
  7407. ,MESSAGE_TYPE_CALLRESULT
  7408. ,uuid
  7409. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7410. json_object_put(ExtendedTriggerMessage);
  7411. LWS_Send(message);
  7412. return result;
  7413. }
  7414. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7415. {
  7416. mtrace();
  7417. int result = PASS;
  7418. char message[4096]={0};
  7419. json_object *GetInstalledCertificateIds = json_object_new_object();
  7420. json_object *certificateHashDataDatas = json_object_new_array();
  7421. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7422. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7423. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7424. {
  7425. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7426. {
  7427. json_object *certificateHashData = json_object_new_object();
  7428. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7429. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7430. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7431. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7432. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7433. }
  7434. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7435. }
  7436. else
  7437. {
  7438. json_object_put(certificateHashDataDatas);
  7439. }
  7440. sprintf(message,"[%d,\"%s\",%s]"
  7441. ,MESSAGE_TYPE_CALLRESULT
  7442. ,uuid
  7443. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7444. json_object_put(GetInstalledCertificateIds);
  7445. LWS_Send(message);
  7446. return result;
  7447. }
  7448. int sendGetLogConfirmation(char *uuid)
  7449. {
  7450. mtrace();
  7451. int result = PASS;
  7452. char message[4096]={0};
  7453. json_object *GetLog = json_object_new_object();
  7454. DEBUG_INFO("sendGetLogConfirmation...\n");
  7455. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7456. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7457. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7458. sprintf(message,"[%d,\"%s\",%s]"
  7459. ,MESSAGE_TYPE_CALLRESULT
  7460. ,uuid
  7461. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7462. json_object_put(GetLog);
  7463. LWS_Send(message);
  7464. return result;
  7465. }
  7466. int sendInstallCertificateConfirmation(char *uuid)
  7467. {
  7468. mtrace();
  7469. int result = PASS;
  7470. char message[4096]={0};
  7471. json_object *InstallCertificate = json_object_new_object();
  7472. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7473. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7474. sprintf(message,"[%d,\"%s\",%s]"
  7475. ,MESSAGE_TYPE_CALLRESULT
  7476. ,uuid
  7477. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7478. json_object_put(InstallCertificate);
  7479. LWS_Send(message);
  7480. return result;
  7481. }
  7482. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7483. {
  7484. mtrace();
  7485. int result = PASS;
  7486. char message[4096]={0};
  7487. json_object *SignedUpdateFirmware = json_object_new_object();
  7488. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7489. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7490. sprintf(message,"[%d,\"%s\",%s]"
  7491. ,MESSAGE_TYPE_CALLRESULT
  7492. ,uuid
  7493. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7494. json_object_put(SignedUpdateFirmware);
  7495. LWS_Send(message);
  7496. return result;
  7497. }
  7498. int sendUnknownConfirmation(char *uuid)
  7499. {
  7500. mtrace();
  7501. int result = PASS;
  7502. char message[256]={0};
  7503. DEBUG_INFO("sendUnknownConfirmation...\n");
  7504. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7505. LWS_Send(message);
  7506. return result;
  7507. }
  7508. //==========================================
  7509. // Handle server request routine Start
  7510. //==========================================
  7511. int handleCancelReservationRequest(char *uuid, char *payload)
  7512. {
  7513. mtrace();
  7514. int result = FAIL;
  7515. int gunNO = 0;
  7516. int reservationIdInt = -1;
  7517. char comfirmstr[20];
  7518. DEBUG_INFO("handleCancelReservationRequest...\n");
  7519. json_object *CancelReservation;
  7520. CancelReservation = json_tokener_parse(payload);
  7521. if(!is_error(CancelReservation))
  7522. {
  7523. // Required data
  7524. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7525. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7526. }
  7527. json_object_put(CancelReservation);
  7528. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7529. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7530. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7531. if(reservationIdInt != -1)
  7532. {
  7533. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7534. //check Transaction active
  7535. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7537. {
  7538. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7539. {
  7540. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7541. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7542. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7543. {
  7544. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7545. }
  7546. else
  7547. {
  7548. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7549. }
  7550. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7551. goto end;
  7552. }
  7553. }
  7554. for (int index = 0; index < CCS_QUANTITY; index++)
  7555. {
  7556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7557. {
  7558. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7559. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7560. if(gunType[2] == GUN_TYPE_CCS)
  7561. {
  7562. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7563. }
  7564. else
  7565. {
  7566. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7567. }
  7568. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7569. goto end;
  7570. }
  7571. }
  7572. for (int index = 0; index < GB_QUANTITY; index++)
  7573. {
  7574. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7575. {
  7576. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7577. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7578. if(gunType[2] == GUN_TYPE_GBT)
  7579. {
  7580. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7581. }
  7582. else
  7583. {
  7584. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7585. }
  7586. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7587. goto end;
  7588. }
  7589. }
  7590. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7591. {
  7592. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7593. {
  7594. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7595. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7596. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7597. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7598. goto end;
  7599. }
  7600. }
  7601. for (int index = 0; index < AC_QUANTITY; index++)
  7602. {
  7603. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7604. {
  7605. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7606. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7608. {
  7609. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7610. }
  7611. else
  7612. {
  7613. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7614. }
  7615. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7616. goto end;
  7617. }
  7618. }
  7619. }
  7620. //The reservationId does NOT match the reservationId
  7621. sendCancelReservationConfirmation(uuid, comfirmstr);
  7622. end:
  7623. // Fill in ocpp packet uuid
  7624. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7625. return result;
  7626. }
  7627. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. int gunIndex = -1;
  7632. char typeStr[16]={0};
  7633. char comfirmstr[20];
  7634. int specificId = FALSE;
  7635. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7636. json_object *ChangeAvailability;
  7637. ChangeAvailability = json_tokener_parse(payload);
  7638. if(!is_error(ChangeAvailability))
  7639. {
  7640. // Required data
  7641. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7642. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7643. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7644. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7645. }
  7646. json_object_put(ChangeAvailability);
  7647. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7648. {
  7649. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7650. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7651. }
  7652. else if(gunIndex == 0)
  7653. {
  7654. for(int i=0; i < gunTotalNumber; i++)
  7655. {
  7656. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7657. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7658. }
  7659. }
  7660. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7661. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7662. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7663. {
  7664. specificId = TRUE;
  7665. }
  7666. if(specificId == FALSE)
  7667. goto end;
  7668. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7669. {
  7670. //----------------------gunIndex is 0 ------------------------------------------------//
  7671. if(gunIndex == 0)
  7672. {
  7673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7674. {
  7675. for(int i=0; i < gunTotalNumber; i++)
  7676. {
  7677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7678. {
  7679. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7680. {
  7681. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7682. {
  7683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7684. goto end;
  7685. }
  7686. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7687. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7688. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7689. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7690. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7691. {
  7692. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7693. goto end;
  7694. }
  7695. }
  7696. }//END FOR CHAdeMO_QUANTITY
  7697. for (int index = 0; index < CCS_QUANTITY; index++)
  7698. {
  7699. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7700. {
  7701. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7702. {
  7703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7704. goto end;
  7705. }
  7706. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7707. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7708. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7709. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7710. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7711. {
  7712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7713. goto end;
  7714. }
  7715. }
  7716. }//END FOR CCS_QUANTITY
  7717. for (int index = 0; index < GB_QUANTITY; index++)
  7718. {
  7719. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7720. {
  7721. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7722. {
  7723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7724. goto end;
  7725. }
  7726. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7727. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7728. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7729. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7730. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7731. {
  7732. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7733. goto end;
  7734. }
  7735. }
  7736. }// END FOR GB_QUANTITY
  7737. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7738. {
  7739. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7740. {
  7741. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7742. {
  7743. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7744. goto end;
  7745. }
  7746. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7747. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7748. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7749. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7750. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7751. {
  7752. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7753. goto end;
  7754. }
  7755. }
  7756. }// END FOR GENERAL_GUN_QUANTITY
  7757. for (int index = 0; index < AC_QUANTITY; index++)
  7758. {
  7759. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7760. {
  7761. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7762. {
  7763. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7764. goto end;
  7765. }
  7766. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7767. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7768. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7769. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7770. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7771. {
  7772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7773. goto end;
  7774. }
  7775. }
  7776. }//END FOR AC_QUANTITY
  7777. }// END FOR gunTotalNumber
  7778. }
  7779. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7780. {
  7781. for(int i=0; i < gunTotalNumber; i++)
  7782. {
  7783. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7784. {
  7785. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7786. goto end;
  7787. }
  7788. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7789. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7790. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7791. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7792. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7793. {
  7794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7795. goto end;
  7796. }
  7797. }
  7798. }
  7799. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7800. goto end;
  7801. }
  7802. //----------------------gunIndex is not 0 ------------------------------------------------//
  7803. //check Transaction active
  7804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7805. {
  7806. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7807. {
  7808. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7809. {
  7810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7811. goto end;
  7812. }
  7813. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7814. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7815. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7816. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7817. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7818. {
  7819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7820. goto end;
  7821. }
  7822. else
  7823. {
  7824. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7826. goto end;
  7827. }
  7828. }
  7829. }//END FOR CHAdeMO_QUANTITY
  7830. for (int index = 0; index < CCS_QUANTITY; index++)
  7831. {
  7832. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7833. {
  7834. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7835. {
  7836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7837. goto end;
  7838. }
  7839. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7840. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7841. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7842. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7843. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7844. {
  7845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7846. goto end;
  7847. }
  7848. else
  7849. {
  7850. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7852. goto end;
  7853. }
  7854. }
  7855. }//END FOR CCS_QUANTITY
  7856. for (int index = 0; index < GB_QUANTITY; index++)
  7857. {
  7858. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7859. {
  7860. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7861. {
  7862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7863. goto end;
  7864. }
  7865. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7866. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7867. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7868. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7869. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7870. {
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7872. goto end;
  7873. }
  7874. else
  7875. {
  7876. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7878. goto end;
  7879. }
  7880. }
  7881. }// END FOR GB_QUANTITY
  7882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7883. {
  7884. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7885. {
  7886. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7887. {
  7888. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7889. goto end;
  7890. }
  7891. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7892. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7893. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7894. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7895. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7896. {
  7897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7898. goto end;
  7899. }
  7900. else
  7901. {
  7902. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7904. goto end;
  7905. }
  7906. }
  7907. }// END FOR GENERAL_GUN_QUANTITY
  7908. for (int index = 0; index < AC_QUANTITY; index++)
  7909. {
  7910. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7911. {
  7912. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7913. {
  7914. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7915. goto end;
  7916. }
  7917. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7918. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7919. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7920. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7921. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7922. {
  7923. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7924. goto end;
  7925. }
  7926. else
  7927. {
  7928. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7930. goto end;
  7931. }
  7932. }
  7933. }//END FOR AC_QUANTITY
  7934. }//END FOR AvailabilityTypeStr[Inoperative]
  7935. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7936. {
  7937. //----------------------gunIndex is 0 ------------------------------------------------//
  7938. if(gunIndex == 0)
  7939. {
  7940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7941. {
  7942. for(int i=0; i < gunTotalNumber; i++)
  7943. {
  7944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7945. {
  7946. 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
  7947. {
  7948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7949. goto end;
  7950. }
  7951. }//END FOR CHAdeMO_QUANTITY
  7952. for (int index = 0; index < CCS_QUANTITY; index++)
  7953. {
  7954. 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
  7955. {
  7956. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7957. goto end;
  7958. }
  7959. }//END FOR CCS_QUANTITY
  7960. for (int index = 0; index < GB_QUANTITY; index++)
  7961. {
  7962. 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
  7963. {
  7964. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7965. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7966. goto end;
  7967. }
  7968. }// END FOR GB_QUANTITY
  7969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7970. {
  7971. 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
  7972. {
  7973. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7974. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7975. goto end;
  7976. }
  7977. }// END FOR GENERAL_GUN_QUANTITY
  7978. for (int index = 0; index < AC_QUANTITY; index++)
  7979. {
  7980. 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
  7981. {
  7982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7983. goto end;
  7984. }
  7985. }//END FOR CHAdeMO_QUANTITY
  7986. }// END FOR gunTotalNumber
  7987. }
  7988. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7989. {
  7990. for(int i=0; i < gunTotalNumber; i++)
  7991. {
  7992. for (int index = 0; index < AC_QUANTITY; index++)
  7993. {
  7994. 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
  7995. {
  7996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7997. goto end;
  7998. }
  7999. }//END FOR CHAdeMO_QUANTITY
  8000. } // END FOR gunTotalNumber
  8001. }
  8002. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8003. goto end;
  8004. }
  8005. //----------------------gunIndex is not 0 ------------------------------------------------//
  8006. //check Transaction active
  8007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8008. {
  8009. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8010. {
  8011. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8012. goto end;
  8013. }
  8014. }//END FOR CHAdeMO_QUANTITY
  8015. for (int index = 0; index < CCS_QUANTITY; index++)
  8016. {
  8017. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8018. {
  8019. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8020. goto end;
  8021. }
  8022. }//END FOR CCS_QUANTITY
  8023. for (int index = 0; index < GB_QUANTITY; index++)
  8024. {
  8025. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8026. {
  8027. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8028. goto end;
  8029. }
  8030. }// END FOR GB_QUANTITY
  8031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8032. {
  8033. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8034. {
  8035. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8036. goto end;
  8037. }
  8038. }// END FOR GENERAL_GUN_QUANTITY
  8039. for (int index = 0; index < AC_QUANTITY; index++)
  8040. {
  8041. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8042. {
  8043. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8044. goto end;
  8045. }
  8046. }//END FOR AC_QUANTITY
  8047. }//END FOR AvailabilityTypeStr[Operative]
  8048. end:
  8049. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8050. {
  8051. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8052. }
  8053. else
  8054. {
  8055. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8056. }
  8057. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8058. {
  8059. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8060. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8061. }
  8062. else if(gunIndex == 0)
  8063. {
  8064. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8065. {
  8066. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8067. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8068. }
  8069. }
  8070. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8071. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8072. return result;
  8073. }
  8074. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8075. {
  8076. mtrace();
  8077. int valueInvalid = NO;
  8078. int result = FAIL;
  8079. char keystr[40]={0};
  8080. char valuestr[501]={0}; //value should be limited in 500 bytes
  8081. char comfirmstr[20]={0};
  8082. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8083. json_object *ChangeConfiguration;
  8084. ChangeConfiguration = json_tokener_parse(payload);
  8085. if(!is_error(ChangeConfiguration))
  8086. {
  8087. // Required data
  8088. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8089. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8090. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8091. {
  8092. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8093. }
  8094. else
  8095. {
  8096. valueInvalid = YES;
  8097. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8098. }
  8099. }
  8100. json_object_put(ChangeConfiguration);
  8101. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8102. {
  8103. DEBUG_ERROR("Payload is null or not accepted.\n");
  8104. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8105. }
  8106. else
  8107. {
  8108. int status = setKeyValue(keystr, valuestr);
  8109. switch(status)
  8110. {
  8111. case ConfigurationStatus_Accepted:
  8112. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8113. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8114. StoreConfigurationTable();
  8115. break;
  8116. case RebootRequired:
  8117. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8118. StoreConfigurationTable();
  8119. break;
  8120. case NotSupported:
  8121. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8122. break;
  8123. case ConfigurationStatus_Rejected:
  8124. default:
  8125. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8126. break;
  8127. }
  8128. }
  8129. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8130. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8131. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8132. {
  8133. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8134. SetOcppConnStatus(FALSE);
  8135. }
  8136. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8137. {
  8138. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8139. }
  8140. return result;
  8141. }
  8142. int handleClearCacheRequest(char *uuid, char *payload)
  8143. {
  8144. mtrace();
  8145. int result = FAIL;
  8146. char comfirmstr[20];
  8147. char rmFileCmd[100]={0};
  8148. struct stat stats;
  8149. DEBUG_INFO("handleClearCacheRequest...\n");
  8150. stat("/Storage/OCPP_PH", &stats);
  8151. // Check for directory existence
  8152. if (S_ISDIR(stats.st_mode) == 1)
  8153. {}
  8154. else
  8155. {
  8156. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8157. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8158. system(rmFileCmd);
  8159. }
  8160. if(OCPP_cleanLocalCache())
  8161. {
  8162. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8163. }
  8164. else
  8165. {
  8166. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8167. }
  8168. sendClearCacheConfirmation(uuid, comfirmstr);
  8169. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8170. return result;
  8171. }
  8172. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8173. {
  8174. mtrace();
  8175. int result = FAIL;
  8176. int resultRename;
  8177. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8178. char chargingProfilePurposeStr[26]={0};
  8179. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8180. char tempchargingProfilePurposeStr[26]={0};
  8181. char str[100]={0};
  8182. char fname[200]={0};
  8183. char comfirmstr[20]={0};
  8184. char word[1600]={0};
  8185. int clearflag = FALSE;
  8186. int chargingProfileIdIsNULL = FALSE;
  8187. int connectorIsNULL = FALSE;
  8188. int chargingProfilePurposeIsNULL = FALSE;
  8189. int stackLevelIsNULL = FALSE;
  8190. //int GotoEnd = FALSE;
  8191. FILE *fptr1, *fptr2;
  8192. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8193. int n_chargingProfile=0;
  8194. int isEmptyFile = FALSE;
  8195. char sLineWord[1600]={0};
  8196. char chargingProfiles[10][100]={0};
  8197. int ChargeProfileCount = 0;
  8198. int ch;
  8199. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8200. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8201. json_object *ClearChargingProfile;
  8202. ClearChargingProfile = json_tokener_parse(payload);
  8203. if(!is_error(ClearChargingProfile))
  8204. {
  8205. // Optional data
  8206. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8207. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8208. else
  8209. chargingProfileIdIsNULL = TRUE;
  8210. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8211. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8212. else
  8213. connectorIsNULL = TRUE;
  8214. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8215. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8216. else
  8217. chargingProfilePurposeIsNULL = TRUE;
  8218. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8219. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8220. else
  8221. stackLevelIsNULL = TRUE;
  8222. }
  8223. json_object_put(ClearChargingProfile);
  8224. if(connectorIsNULL == FALSE)
  8225. {
  8226. switch(connectorIdInt)
  8227. {
  8228. case 0:
  8229. if(chargingProfilePurposeIsNULL == TRUE)
  8230. {
  8231. int l = 0;
  8232. strcpy(fname, ChargePointMaxProfile_JSON);
  8233. if((access(fname,F_OK))!=-1)
  8234. {
  8235. strcpy(chargingProfiles[l], fname);
  8236. l = l + 1;
  8237. }
  8238. strcpy(fname, TxDefaultProfile_0_JSON);
  8239. if((access(fname,F_OK))!=-1)
  8240. {
  8241. strcpy(chargingProfiles[l], fname);
  8242. l = l + 1;
  8243. }
  8244. ChargeProfileCount = l;
  8245. }
  8246. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8247. {
  8248. strcpy(fname, ChargePointMaxProfile_JSON);
  8249. if((access(fname,F_OK))!=-1)
  8250. {
  8251. strcpy(chargingProfiles[0], fname);
  8252. ChargeProfileCount = 1;
  8253. }
  8254. }
  8255. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8256. {
  8257. strcpy(fname, TxDefaultProfile_0_JSON);
  8258. if((access(fname,F_OK))!=-1)
  8259. {
  8260. strcpy(chargingProfiles[0], fname);
  8261. ChargeProfileCount = 1;
  8262. }
  8263. }
  8264. break;
  8265. default:
  8266. if(chargingProfilePurposeIsNULL == TRUE)
  8267. {
  8268. int m = 0;
  8269. memset(fname, 0, ARRAY_SIZE(fname));
  8270. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8271. if((access(fname,F_OK))!=-1)
  8272. {
  8273. strcpy(chargingProfiles[m], fname);
  8274. m = m + 1;
  8275. }
  8276. memset(fname, 0, ARRAY_SIZE(fname));
  8277. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8278. if((access(fname,F_OK))!=-1)
  8279. {
  8280. strcpy(chargingProfiles[m], fname);
  8281. m = m + 1;
  8282. }
  8283. ChargeProfileCount = m;
  8284. }
  8285. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8286. {
  8287. //strcpy(fname, TxDefaultProfile_1_JSON);
  8288. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8289. if((access(fname,F_OK))!=-1)
  8290. {
  8291. strcpy(chargingProfiles[0], fname);
  8292. ChargeProfileCount = 1;
  8293. }
  8294. }
  8295. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8296. {
  8297. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8298. if((access(fname,F_OK))!=-1)
  8299. {
  8300. strcpy(chargingProfiles[0], fname);
  8301. ChargeProfileCount = 1;
  8302. }
  8303. //strcpy(fname, TxProfile_1_JSON);
  8304. }
  8305. //strcpy(fname, ChargePointMaxProfile_JSON );
  8306. break;
  8307. }
  8308. }
  8309. else // Check all Charging Profiles
  8310. {
  8311. int i = 0;
  8312. char fnametemp[200]={0};
  8313. ChargeProfileCount = 0;
  8314. //Check ChargePointMaxProfile.json exit
  8315. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8316. {
  8317. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8318. i = i + 1;
  8319. }
  8320. //Check TxDefaultProfile_0.json exit
  8321. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8322. {
  8323. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8324. i = i + 1;
  8325. }
  8326. //Check TxDefaultProfile_%d.json
  8327. for(int j=1; j <= gunTotalNumber; j++)
  8328. {
  8329. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8330. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8331. if((access(fnametemp,F_OK))!=-1)
  8332. {
  8333. strcpy(chargingProfiles[i], fnametemp);
  8334. i = i + 1;
  8335. }
  8336. }
  8337. //Check TxProfile_%d.json
  8338. for(int j=1; j <= gunTotalNumber; j++)
  8339. {
  8340. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8341. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8342. if((access(fnametemp,F_OK))!=-1)
  8343. {
  8344. strcpy(chargingProfiles[i], fnametemp);
  8345. i = i + 1;
  8346. }
  8347. }
  8348. ChargeProfileCount = i;
  8349. }// End connectorIsNULL is TRUE
  8350. if(ChargeProfileCount == 0)
  8351. {
  8352. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8353. goto end;
  8354. }
  8355. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8356. {
  8357. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8358. goto end;
  8359. }
  8360. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8361. {
  8362. memset(str, 0, ARRAY_SIZE(str));
  8363. // clear temp file
  8364. sprintf(str,"rm -f %s",temp);
  8365. system(str);
  8366. for(int k=0; k < ChargeProfileCount; k++)
  8367. {
  8368. memset(str, 0, ARRAY_SIZE(str));
  8369. //clear file in C
  8370. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8371. system(str);
  8372. }
  8373. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8374. goto end;
  8375. }
  8376. else if(connectorIsNULL == TRUE)
  8377. {
  8378. for(int k=0; k < ChargeProfileCount; k++)
  8379. {
  8380. fptr1 = fopen(chargingProfiles[k], "r");
  8381. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8382. //Check Charging Profile Count
  8383. while(fscanf(fptr1, "%s", word) != EOF)
  8384. {
  8385. //DEBUG_INFO("word=%s\n",word);
  8386. if(strstr(word, "chargingProfileId")!= NULL)
  8387. {
  8388. //DEBUG_INFO("test chargingProfileId \n");
  8389. n_chargingProfile = n_chargingProfile + 1;
  8390. //DEBUG_INFO("chargingProfileId Found\n");
  8391. }
  8392. }
  8393. rewind(fptr1);
  8394. //search Charging Profile Element
  8395. //int i= 0;
  8396. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8397. {
  8398. json_object *tmpProfilee;
  8399. tmpProfilee = json_tokener_parse(sLineWord);
  8400. if(!is_error(tmpProfilee))
  8401. {
  8402. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8403. {
  8404. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8405. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8406. }
  8407. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8408. {
  8409. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8410. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8411. }
  8412. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8413. {
  8414. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8415. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8416. }
  8417. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8418. {
  8419. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8420. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8421. }
  8422. }
  8423. json_object_put(tmpProfilee);
  8424. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8425. {
  8426. //------- not write to fptr2-------//
  8427. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8428. //clearflag = TRUE;
  8429. }
  8430. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8431. {
  8432. //------- not write to fptr2-------//
  8433. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8434. }
  8435. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8436. {
  8437. //------- not write to fptr2-------//
  8438. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8439. }
  8440. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8441. {
  8442. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8443. }
  8444. else
  8445. {
  8446. fprintf(fptr2, sLineWord);//writing data into file
  8447. }
  8448. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8449. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8450. if(clearflag == TRUE)
  8451. {
  8452. fclose(fptr1);
  8453. fclose(fptr2);
  8454. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8455. system(str);
  8456. // clear temp file
  8457. sprintf(str,"rm -f %s",temp);
  8458. system(str);
  8459. }
  8460. else
  8461. {
  8462. fclose(fptr1);
  8463. fclose(fptr2);
  8464. memset(str, 0, ARRAY_SIZE(str));
  8465. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8466. system(str);
  8467. resultRename = rename(temp, chargingProfiles[k]);
  8468. if(resultRename == 0)
  8469. {
  8470. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8471. }
  8472. else
  8473. {
  8474. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8475. }
  8476. if(comfirmstr[0]== 0)
  8477. {
  8478. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8479. }
  8480. //Check chargingProfile is empty file
  8481. /*------ Read the file ----------------*/
  8482. fptr1=fopen(chargingProfiles[k],"r");
  8483. ch=fgetc(fptr1);
  8484. rewind(fptr1);
  8485. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8486. if(ch!=EOF)
  8487. {
  8488. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8489. {
  8490. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8491. if(sLineWord[0]=='\0')
  8492. {
  8493. isEmptyFile = TRUE;
  8494. break;
  8495. }
  8496. else
  8497. {
  8498. isEmptyFile = FALSE;
  8499. break;
  8500. }
  8501. }
  8502. }
  8503. else
  8504. isEmptyFile = TRUE;
  8505. fclose(fptr1);
  8506. if(isEmptyFile == TRUE)
  8507. {
  8508. memset(str, 0, ARRAY_SIZE(str));
  8509. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8510. system(str);
  8511. }
  8512. }
  8513. }// End of while(int k=0; k < ChargePointCount; k++)
  8514. }
  8515. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8516. {
  8517. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8518. for(int k=0; k < ChargeProfileCount; k++)
  8519. {
  8520. fptr1 = fopen(chargingProfiles[k], "r");
  8521. fptr2 = fopen(temp, "w+");
  8522. //Check Charging Profile Count
  8523. while(fscanf(fptr1, "%s", word) != EOF)
  8524. {
  8525. //DEBUG_INFO("word=%s\n",word);
  8526. if(strstr(word, "chargingProfileId")!= NULL)
  8527. {
  8528. n_chargingProfile = n_chargingProfile + 1;
  8529. }
  8530. }
  8531. rewind(fptr1);
  8532. //search Charging Profile Element
  8533. //int i= 0;
  8534. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8535. {
  8536. json_object *tmpProfilee;
  8537. tmpProfilee = json_tokener_parse(sLineWord);
  8538. if(!is_error(tmpProfilee))
  8539. {
  8540. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8541. {
  8542. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8543. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8544. }
  8545. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8546. {
  8547. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8548. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8549. }
  8550. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8551. {
  8552. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8553. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8554. }
  8555. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8556. {
  8557. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8558. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8559. }
  8560. }
  8561. json_object_put(tmpProfilee);
  8562. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8563. {
  8564. //------- not write to fptr2-------//
  8565. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8566. //clearflag = TRUE;
  8567. }
  8568. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8569. {
  8570. //------- not write to fptr2-------//
  8571. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8572. }
  8573. else if(stackLevelIsNULL == TRUE)
  8574. {
  8575. //Clear Whole File
  8576. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8577. clearflag = TRUE;
  8578. break;
  8579. }
  8580. else
  8581. {
  8582. fprintf(fptr2, sLineWord);//writing data into file
  8583. }
  8584. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8585. }
  8586. if(clearflag == TRUE)
  8587. {
  8588. fclose(fptr1);
  8589. fclose(fptr2);
  8590. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8591. system(str);
  8592. // clear temp file
  8593. sprintf(str,"rm -f %s",temp);
  8594. system(str);
  8595. }
  8596. else
  8597. {
  8598. fclose(fptr1);
  8599. fclose(fptr2);
  8600. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8601. system(str);
  8602. resultRename = rename(temp, chargingProfiles[k]);
  8603. if(resultRename == 0)
  8604. {
  8605. DEBUG_INFO("File ChargingProfile renamed successfully");
  8606. }
  8607. else
  8608. {
  8609. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8610. }
  8611. if(comfirmstr[0]== 0)
  8612. {
  8613. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8614. }
  8615. //Check chargingProfile is empty file
  8616. /*------ Read the file ----------------*/
  8617. fptr1=fopen(chargingProfiles[k],"r");
  8618. ch=fgetc(fptr1);
  8619. rewind(fptr1);
  8620. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8621. if(ch!=EOF)
  8622. {
  8623. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8624. {
  8625. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8626. if(sLineWord[0]=='\0')
  8627. {
  8628. isEmptyFile = TRUE;
  8629. break;
  8630. }
  8631. else
  8632. {
  8633. isEmptyFile = FALSE;
  8634. break;
  8635. }
  8636. }
  8637. }
  8638. else
  8639. isEmptyFile = TRUE;
  8640. fclose(fptr1);
  8641. if(isEmptyFile == TRUE)
  8642. {
  8643. memset(str, 0, ARRAY_SIZE(str));
  8644. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8645. system(str);
  8646. }
  8647. /*------- End of reading ---------------*/
  8648. }
  8649. } // while(int k=0; k < ChargeProfileCount; k++)
  8650. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8651. end:
  8652. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8653. {
  8654. if(connectorIdInt == 0)
  8655. {
  8656. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8657. {
  8658. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8659. }
  8660. }
  8661. else
  8662. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8663. }
  8664. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8665. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8666. return result;
  8667. }
  8668. void createFirmwareVersionByDataTransfer(void)
  8669. {
  8670. json_object *FirmwareDataTransfer = json_object_new_object();
  8671. // AC & DC model
  8672. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8673. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8674. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8675. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8676. // DC model
  8677. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8678. {
  8679. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8680. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8681. (gunType[3] != GUN_TYPE_UNKNOWN))
  8682. {
  8683. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8684. }
  8685. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8686. {
  8687. // DS DM DW
  8688. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8689. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8690. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8691. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8692. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8693. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8694. }
  8695. else
  8696. {
  8697. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8698. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8699. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8700. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8701. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8702. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8703. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8704. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8705. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8706. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8707. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8708. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8709. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8710. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8711. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8712. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8713. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8714. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8715. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8716. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8717. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8718. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8719. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8720. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8721. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8722. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8723. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8724. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8725. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8726. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8727. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8728. }
  8729. }
  8730. // 4G model
  8731. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8732. {
  8733. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8734. }
  8735. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8736. json_object_put(FirmwareDataTransfer);
  8737. }
  8738. int handleDataTransferRequest(char *uuid, char *payload)
  8739. {
  8740. mtrace();
  8741. json_object *response = json_object_new_object();
  8742. int result = FAIL;
  8743. char tempvendorId[255]={0};
  8744. char tempmessageId[50]={0};
  8745. char tempdata[512]={0};
  8746. char message[2048]={0};
  8747. DEBUG_INFO("handleDataTransferRequest...\n");
  8748. if((uuid != NULL) && (payload != NULL))
  8749. {
  8750. json_object *DataTransfer;
  8751. DataTransfer = json_tokener_parse(payload);
  8752. if(!is_error(DataTransfer))
  8753. {
  8754. // Required data
  8755. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8756. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8757. // Optional data
  8758. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8759. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8760. if(json_object_object_get(DataTransfer, "data") != NULL)
  8761. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8762. result = PASS;
  8763. }
  8764. json_object_put(DataTransfer);
  8765. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8766. {
  8767. // Send all moudle firmware version on EVSE
  8768. createFirmwareVersionByDataTransfer();
  8769. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8770. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8771. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8772. json_object_put(response);
  8773. }
  8774. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8775. {
  8776. system("/usr/bin/run_tmate_restart.sh &");
  8777. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8778. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8779. json_object_put(response);
  8780. }
  8781. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8782. {
  8783. json_object *data;
  8784. data = json_tokener_parse(tempdata);
  8785. if(!is_error(data))
  8786. {
  8787. 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))
  8788. {
  8789. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8790. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8791. if(json_object_object_get(data, "SOC") != NULL)
  8792. {
  8793. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8794. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8795. }
  8796. if(json_object_object_get(data, "Energy") != NULL)
  8797. {
  8798. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8799. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8800. }
  8801. if(json_object_object_get(data, "Duration") != NULL)
  8802. {
  8803. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8804. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8805. }
  8806. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8807. }
  8808. else
  8809. {
  8810. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8811. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8812. }
  8813. }
  8814. else
  8815. {
  8816. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8817. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8818. }
  8819. json_object_put(data);
  8820. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8821. json_object_put(response);
  8822. }
  8823. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8824. {
  8825. json_object *data;
  8826. data = json_tokener_parse(tempdata);
  8827. if(!is_error(data))
  8828. {
  8829. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8830. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8831. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8832. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8833. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8834. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8835. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8836. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8837. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8838. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8839. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8840. }
  8841. else
  8842. {
  8843. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8844. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8845. }
  8846. json_object_put(data);
  8847. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8848. json_object_put(response);
  8849. }
  8850. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8851. {
  8852. json_object *data;
  8853. data = json_tokener_parse(tempdata);
  8854. if(!is_error(data))
  8855. {
  8856. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8857. if(json_object_object_get(data, "idToken") != NULL)
  8858. {
  8859. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8860. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8861. }
  8862. if(json_object_object_get(data, "price") != NULL)
  8863. {
  8864. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8865. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8866. }
  8867. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8868. }
  8869. else
  8870. {
  8871. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8872. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8873. }
  8874. json_object_put(data);
  8875. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8876. json_object_put(response);
  8877. }
  8878. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8879. {
  8880. json_object *data;
  8881. data = json_tokener_parse(tempdata);
  8882. if(!is_error(data))
  8883. {
  8884. if(json_object_object_get(data, "txId") != NULL)
  8885. {
  8886. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8887. for(int idx = 0;idx<gunTotalNumber;idx++)
  8888. {
  8889. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8890. {
  8891. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8892. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8893. if(json_object_object_get(data, "description") != NULL)
  8894. {
  8895. // California pricing V1.0
  8896. DEBUG_INFO("California pricing V1.0\n");
  8897. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8898. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8899. }
  8900. else
  8901. {
  8902. // California pricing V1.1
  8903. DEBUG_INFO("California pricing V1.1\n");
  8904. if(json_object_object_get(data, "timestamp") != NULL)
  8905. {
  8906. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8907. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8908. }
  8909. if(json_object_object_get(data, "meterValue") != NULL)
  8910. {
  8911. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8912. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8913. }
  8914. if(json_object_object_get(data, "cost") != NULL)
  8915. {
  8916. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8917. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8918. }
  8919. if(json_object_object_get(data, "state") != NULL)
  8920. {
  8921. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8922. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8923. }
  8924. if(json_object_object_get(data, "chargingPrice") != NULL)
  8925. {
  8926. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8927. {
  8928. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8929. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8930. }
  8931. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8932. {
  8933. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8934. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8935. }
  8936. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8937. {
  8938. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8939. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8940. }
  8941. }
  8942. if(json_object_object_get(data, "idlePrice") != NULL)
  8943. {
  8944. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8945. {
  8946. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8947. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8948. }
  8949. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8950. {
  8951. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8952. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8953. }
  8954. }
  8955. if(json_object_object_get(data, "nextPeriod") != NULL)
  8956. {
  8957. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8958. {
  8959. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8960. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8961. }
  8962. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8963. {
  8964. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8965. {
  8966. 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")));
  8967. 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"));
  8968. }
  8969. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8970. {
  8971. 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")));
  8972. 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"));
  8973. }
  8974. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8975. {
  8976. 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")));
  8977. 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"));
  8978. }
  8979. }
  8980. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8981. {
  8982. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8983. {
  8984. 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")));
  8985. 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"));
  8986. }
  8987. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8988. {
  8989. 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")));
  8990. 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"));
  8991. }
  8992. }
  8993. }
  8994. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8995. {
  8996. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8997. {
  8998. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8999. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9000. }
  9001. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9002. {
  9003. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9004. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9005. }
  9006. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9007. {
  9008. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9009. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9010. }
  9011. }
  9012. }
  9013. }
  9014. }
  9015. }
  9016. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9017. }
  9018. else
  9019. {
  9020. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9021. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9022. }
  9023. json_object_put(data);
  9024. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9025. json_object_put(response);
  9026. }
  9027. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9028. {
  9029. json_object *data;
  9030. data = json_tokener_parse(tempdata);
  9031. if(!is_error(data))
  9032. {
  9033. if(json_object_object_get(data, "txId") != NULL)
  9034. {
  9035. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9036. for(int idx = 0;idx<gunTotalNumber;idx++)
  9037. {
  9038. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9039. {
  9040. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9041. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9042. if(json_object_object_get(data, "description") != NULL)
  9043. {
  9044. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9045. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9046. }
  9047. }
  9048. }
  9049. }
  9050. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9051. }
  9052. else
  9053. {
  9054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9055. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9056. }
  9057. json_object_put(data);
  9058. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9059. json_object_put(response);
  9060. }
  9061. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9062. {
  9063. json_object *data;
  9064. data = json_tokener_parse(tempdata);
  9065. if(!is_error(data))
  9066. {
  9067. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9068. if(json_object_object_get(data, "Content_Type") != NULL)
  9069. {
  9070. 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))
  9071. {
  9072. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9073. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9074. {
  9075. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9076. }
  9077. }
  9078. else
  9079. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9080. }
  9081. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9082. }
  9083. else
  9084. {
  9085. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9086. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9087. }
  9088. json_object_put(data);
  9089. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9090. json_object_put(response);
  9091. }
  9092. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9093. {
  9094. json_object *data;
  9095. data = json_tokener_parse(tempdata);
  9096. if(!is_error(data))
  9097. {
  9098. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9099. if(json_object_object_get(data, "ConnectorId") != NULL)
  9100. {
  9101. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9102. }
  9103. if(json_object_object_get(data, "SerialNo") != NULL)
  9104. {
  9105. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9106. }
  9107. if(json_object_object_get(data, "Page_Index") != NULL)
  9108. {
  9109. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9110. }
  9111. if(json_object_object_get(data, "Duration") != NULL)
  9112. {
  9113. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9114. }
  9115. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9116. }
  9117. else
  9118. {
  9119. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9120. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9121. }
  9122. json_object_put(data);
  9123. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9124. json_object_put(response);
  9125. }
  9126. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9127. {
  9128. json_object *data;
  9129. data = json_tokener_parse(tempdata);
  9130. if(!is_error(data))
  9131. {
  9132. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9133. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9134. {
  9135. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9136. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9137. else
  9138. {
  9139. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9140. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9141. }
  9142. }
  9143. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9144. {
  9145. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9146. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9147. else
  9148. {
  9149. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9150. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9151. }
  9152. }
  9153. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9154. {
  9155. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9156. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9157. else
  9158. {
  9159. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9160. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9161. }
  9162. }
  9163. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9164. {
  9165. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9166. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9167. else
  9168. {
  9169. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9170. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9171. }
  9172. }
  9173. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9174. {
  9175. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9176. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  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, "OfflinePolicy") != NULL)
  9184. {
  9185. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9186. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9187. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9188. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9189. else
  9190. {
  9191. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9192. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9193. }
  9194. }
  9195. if(json_object_object_get(data, "isAuthentication") != NULL)
  9196. {
  9197. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9198. {
  9199. case 0:
  9200. case 1:
  9201. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9202. break;
  9203. default:
  9204. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9205. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9206. break;
  9207. }
  9208. }
  9209. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9210. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9211. }
  9212. else
  9213. {
  9214. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9215. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9216. }
  9217. json_object_put(data);
  9218. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9219. json_object_put(response);
  9220. }
  9221. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9222. {
  9223. json_object *data;
  9224. data = json_tokener_parse(tempdata);
  9225. if(!is_error(data))
  9226. {
  9227. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9228. if(json_object_object_get(data, "stationName") != NULL)
  9229. {
  9230. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  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("station_name data can not get."));
  9236. }
  9237. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9238. {
  9239. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9240. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9241. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9242. }
  9243. }
  9244. else
  9245. {
  9246. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9247. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9248. }
  9249. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9250. json_object_put(response);
  9251. }
  9252. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9253. {
  9254. json_object *data;
  9255. data = json_tokener_parse(tempdata);
  9256. if(!is_error(data))
  9257. {
  9258. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9259. if(json_object_object_get(data, "weatherId") != NULL)
  9260. {
  9261. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9262. }
  9263. else
  9264. {
  9265. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9266. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9267. }
  9268. if(json_object_object_get(data, "Temperature") != NULL)
  9269. {
  9270. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9271. }
  9272. else
  9273. {
  9274. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9275. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9276. }
  9277. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9278. {
  9279. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9280. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9281. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9282. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9283. }
  9284. }
  9285. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9286. {
  9287. json_object *data;
  9288. data = json_tokener_parse(tempdata);
  9289. if(!is_error(data))
  9290. {
  9291. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9292. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9293. {
  9294. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9295. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9296. }
  9297. else
  9298. {
  9299. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9300. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9301. }
  9302. }
  9303. else
  9304. {
  9305. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9306. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9307. }
  9308. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9309. json_object_put(response);
  9310. }
  9311. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9312. {
  9313. json_object *data;
  9314. data = json_tokener_parse(tempdata);
  9315. if(!is_error(data))
  9316. {
  9317. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9318. {
  9319. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9320. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9321. if(gun_index < gunTotalNumber)
  9322. {
  9323. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9324. {
  9325. json_object *responsedata = json_object_new_object();
  9326. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9327. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9328. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9329. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9330. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9331. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  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("txId doesn't match the current transactionId."));
  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("ConnectorId is invalid."));
  9343. }
  9344. }
  9345. else
  9346. {
  9347. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9348. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9349. }
  9350. }
  9351. else
  9352. {
  9353. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9354. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9355. }
  9356. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9357. json_object_put(response);
  9358. }
  9359. else
  9360. {
  9361. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9362. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9363. }
  9364. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9365. json_object_put(response);
  9366. }
  9367. else
  9368. {
  9369. // Can not find valid message id
  9370. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9371. }
  9372. }
  9373. else
  9374. {
  9375. // Payload is null
  9376. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9377. }
  9378. LWS_Send(message);
  9379. return result;
  9380. }
  9381. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9382. {
  9383. mtrace();
  9384. int result = FAIL;
  9385. int connectorIdInt, durationInt;
  9386. char chargingRateUnitStr[4]={0};
  9387. char comfirmstr[20];
  9388. int confirmPeriods = 0;
  9389. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9390. json_object *GetCompositeSchedule;
  9391. GetCompositeSchedule = json_tokener_parse(payload);
  9392. if(!is_error(GetCompositeSchedule))
  9393. {
  9394. // Required data
  9395. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9396. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9397. else
  9398. connectorIdInt = -1;
  9399. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9400. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9401. else
  9402. durationInt = 86400;
  9403. // Optional data
  9404. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9405. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9406. }
  9407. json_object_put(GetCompositeSchedule);
  9408. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9409. if((connectorIdInt == 0) ||
  9410. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9411. {
  9412. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9413. struct StructChargingProfile tmpProfile[1];
  9414. if(strstr(chargingRateUnitStr, "W") != NULL)
  9415. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9416. else
  9417. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9418. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9419. {
  9420. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9421. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9422. }
  9423. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9424. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9425. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9426. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9427. {
  9428. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9429. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9430. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9431. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9432. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9433. {
  9434. confirmPeriods = idx;
  9435. break;
  9436. }
  9437. }
  9438. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9439. {
  9440. confirmPeriods += 1;
  9441. }
  9442. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9443. }
  9444. else
  9445. {
  9446. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9447. }
  9448. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9449. return result;
  9450. }
  9451. int handleGetConfigurationRequest(char *uuid, char *payload)
  9452. {
  9453. mtrace();
  9454. int result = FAIL;
  9455. int MaxKeySupported = 0;
  9456. int n_keys = 0;
  9457. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9458. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9459. json_object *GetConfiguration;
  9460. GetConfiguration = json_tokener_parse(payload);
  9461. if(!is_error(GetConfiguration))
  9462. {
  9463. // Optional data
  9464. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9465. {
  9466. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9467. {
  9468. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9469. n_keys = idx + 1;
  9470. }
  9471. }
  9472. }
  9473. json_object_put(GetConfiguration);
  9474. UnknownKeynum = 0;
  9475. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9476. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9477. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9478. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9479. if(n_keys != 0)
  9480. {
  9481. for(int i=0;i<n_keys;i++)
  9482. {
  9483. getKeyValue(requestKey[i]);
  9484. }
  9485. }
  9486. else
  9487. {
  9488. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9489. getKeyValue("");
  9490. }
  9491. processUnkownKey();
  9492. sendGetConfigurationConfirmation(uuid);
  9493. return result;
  9494. }
  9495. static char fnamePlusPath[100]={0};
  9496. static char fnamePWithNoPath[60]={0};
  9497. void checkUploadLog(void)
  9498. {
  9499. FILE *fp;
  9500. /* Open the command for reading. */
  9501. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9502. if (fp == NULL) {
  9503. DEBUG_WARN("Failed to run command\n" );
  9504. exit(1);
  9505. }
  9506. int ftppathlen = 0;
  9507. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9508. int i = 0;
  9509. /* Read the output a line at a time - output it. */
  9510. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9511. if(i==0)
  9512. {
  9513. ftppathlen = strlen(fnamePlusPath);
  9514. DEBUG_INFO("%s\n", fnamePlusPath);
  9515. fnamePlusPath[ftppathlen]='\0';
  9516. break;
  9517. }
  9518. i= i+1;
  9519. }
  9520. /* close */
  9521. pclose(fp);
  9522. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9523. {
  9524. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9525. {
  9526. fnamePlusPath[k]='\0';
  9527. }
  9528. }
  9529. i=1;
  9530. //char fname[60]={0};
  9531. while(i < ftppathlen)
  9532. {
  9533. int len=ftppathlen-i;
  9534. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9535. {
  9536. DEBUG_INFO("compare '/' all right\n");
  9537. break;
  9538. }
  9539. i=i+1;
  9540. }
  9541. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9542. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9543. fnamePWithNoPath[i+1] = '\0';
  9544. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9545. {
  9546. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9547. {
  9548. fnamePWithNoPath[j]='\0';
  9549. }
  9550. }
  9551. FILE* fp1 = fopen(fnamePlusPath, "r");
  9552. if (fp1)
  9553. {
  9554. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9555. // file exists
  9556. fclose(fp1);
  9557. }
  9558. else
  9559. {
  9560. // file doesn't exist
  9561. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9562. }
  9563. }
  9564. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9565. {
  9566. mtrace();
  9567. int result = FAIL;
  9568. time_t CurrentTime;
  9569. struct tm *tm;
  9570. pthread_t th_Status;
  9571. CurrentTime = time(NULL);
  9572. tm = localtime(&CurrentTime);
  9573. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9574. 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);
  9575. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9576. if(!interLock.isGetDiagnosticGoing)
  9577. {
  9578. interLock.isGetDiagnosticGoing = 1;
  9579. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9580. sleep(1);
  9581. }
  9582. else
  9583. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9584. return result;
  9585. }
  9586. void* GetDiagnosticsProcess(void* data)
  9587. {
  9588. pthread_detach(pthread_self());
  9589. mtrace();
  9590. int retriesInt=0, retryIntervalInt=0;
  9591. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9592. 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};
  9593. int port=0;
  9594. int isSuccess = FALSE;
  9595. char ftpbuf[200]={0};
  9596. char cmdBuf[2048];
  9597. struct tm *tmNow;
  9598. time_t CurrentTime;
  9599. struct tm tmStart;
  9600. struct tm tmStop;
  9601. CurrentTime = time(NULL);
  9602. tmNow=localtime(&CurrentTime);
  9603. uint16_t targetYear, targetMonth;
  9604. json_object *GetDiagnostics;
  9605. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9606. GetDiagnostics = json_tokener_parse(data);
  9607. if(!is_error(GetDiagnostics))
  9608. {
  9609. // Required data
  9610. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9611. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9612. // Optional data
  9613. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9614. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9615. else
  9616. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9617. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9618. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9619. else
  9620. retryIntervalInt = 30;
  9621. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9622. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9623. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9624. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9625. }
  9626. json_object_put(GetDiagnostics);
  9627. // Pack log to compress file
  9628. 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) &&
  9629. (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))
  9630. {
  9631. // Pack system log
  9632. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9633. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9634. targetYear = tmStart.tm_year;
  9635. targetMonth = tmStart.tm_mon;
  9636. do
  9637. {
  9638. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9639. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9640. if(targetMonth+1>=13)
  9641. {
  9642. targetYear += 1;
  9643. targetMonth = 1;
  9644. }
  9645. else
  9646. {
  9647. targetMonth += 1;
  9648. }
  9649. }while((targetYear < (tmNow->tm_year+1900)) ||
  9650. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9651. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9652. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9653. system(cmdBuf);
  9654. // Pack charging & event log
  9655. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9656. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9657. targetYear = tmStart.tm_year;
  9658. targetMonth = tmStart.tm_mon;
  9659. do
  9660. {
  9661. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9662. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9663. if(targetMonth+1>=13)
  9664. {
  9665. targetYear += 1;
  9666. targetMonth = 1;
  9667. }
  9668. else
  9669. {
  9670. targetMonth += 1;
  9671. }
  9672. }while((targetYear < (tmNow->tm_year+1900)) ||
  9673. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9674. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9675. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9676. system(cmdBuf);
  9677. // Combine log file
  9678. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9679. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9680. }
  9681. else
  9682. {
  9683. system("exec /root/logPackTools 'log' 6");
  9684. }
  9685. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9686. system(cmdBuf);
  9687. checkUploadLog();
  9688. //****************location*******************/
  9689. if(strcmp(locationstr,"")==0)
  9690. {
  9691. DEBUG_INFO("location is <Empty>!\n");
  9692. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9693. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9694. goto end;
  9695. }
  9696. memset(protocol, 0, ARRAY_SIZE(protocol));
  9697. memset(user, 0, ARRAY_SIZE(user) );
  9698. memset(password, 0, ARRAY_SIZE(password));
  9699. memset(host, 0, ARRAY_SIZE(host));
  9700. memset(path, 0, ARRAY_SIZE(path));
  9701. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9702. memset(host1, 0, ARRAY_SIZE(host1));
  9703. memset(path1, 0, ARRAY_SIZE(path1));
  9704. /*location: ftp://user:password@host:port/path*/
  9705. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9706. if((access(fnamePlusPath,F_OK))!=-1)
  9707. {
  9708. DEBUG_INFO("fnamePlusPath exist.\n");
  9709. }
  9710. else
  9711. {
  9712. DEBUG_INFO("fnamePlusPath not exist!\n");
  9713. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9714. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9715. goto end;
  9716. }
  9717. if(strchr(locationstr,'@')==NULL)
  9718. {
  9719. sscanf(locationstr,
  9720. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9721. protocol, host, &port, path);
  9722. strcpy(user,"anonymous");
  9723. strcpy(password,"");
  9724. }
  9725. else
  9726. {
  9727. //DEBUG_INFO("pch=%s\n", pch);
  9728. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9729. protocol, user, password, host, &port, path);
  9730. }
  9731. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9732. {
  9733. DEBUG_INFO("protocol is not ftp/http ! \n");
  9734. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9735. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9736. goto end;
  9737. }
  9738. if(strncmp(locationstr,"http", 4) == 0)
  9739. {
  9740. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9741. sprintf(ftppath,"/%s", path);
  9742. do
  9743. {
  9744. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9745. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9746. sleep(3);
  9747. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9748. if(!isSuccess)
  9749. {
  9750. DEBUG_INFO("Diagnostics fail.\n");
  9751. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9752. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9753. sleep(retryIntervalInt);
  9754. }
  9755. else
  9756. {
  9757. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9758. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9759. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9760. }
  9761. retriesInt--;
  9762. }while((isSuccess == 0)&&(retriesInt >= 0));
  9763. }
  9764. else
  9765. {
  9766. sscanf(host,"%[^/]%s",host1, path1);
  9767. if(strlen(path) > 0)
  9768. sprintf(ftppath,"/%s", path);
  9769. else
  9770. sprintf(ftppath,"/%s", path1);
  9771. int ftppathlen=strlen(ftppath);
  9772. int i=1;
  9773. char filenametemp[50];
  9774. while(i < ftppathlen)
  9775. {
  9776. int len=ftppathlen-i;
  9777. if(ftppath[len]== 47) // '/' ascll code: 47
  9778. {
  9779. DEBUG_INFO("find '/' all right\n");
  9780. break;
  9781. }
  9782. i=i+1;
  9783. }
  9784. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9785. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9786. filenametemp[i+1] = 0;
  9787. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9788. if(port == 0)
  9789. port = 21;
  9790. do
  9791. {
  9792. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9793. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9794. sleep(3);
  9795. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9796. if(!isSuccess)
  9797. {
  9798. DEBUG_INFO("Diagnostics fail.\n");
  9799. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9800. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9801. sleep(retryIntervalInt);
  9802. }
  9803. else
  9804. {
  9805. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9806. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9807. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9808. }
  9809. retriesInt--;
  9810. }while((!isSuccess)&&(retriesInt >= 0));
  9811. }
  9812. end:
  9813. system("rm -f /mnt/*");
  9814. sleep(5);
  9815. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9816. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9817. interLock.isGetDiagnosticGoing = 0;
  9818. pthread_exit(NULL);
  9819. }
  9820. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9821. {
  9822. mtrace();
  9823. int result = FAIL;
  9824. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9825. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9826. {
  9827. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9828. locallistVersion = -1;
  9829. }
  9830. else
  9831. {
  9832. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9833. OCPP_getListVerion();
  9834. }
  9835. //from db.OCPP_getListVerion
  9836. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9837. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9838. sendGetLocalListVersionConfirmation(uuid,"");
  9839. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9840. return result;
  9841. }
  9842. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9843. {
  9844. mtrace();
  9845. int result = FAIL;
  9846. int connectorIdInt=-1;
  9847. int tempIndex = 0;
  9848. int connectorIdIsNULL, chargingProfileIsNULL;
  9849. char comfirmstr[20]={0};
  9850. char cmdBuf[512];
  9851. json_object *RemoteStartTransaction;
  9852. FILE *fp;
  9853. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9854. if(server_pending == TRUE)
  9855. {
  9856. return 0;
  9857. }
  9858. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9859. RemoteStartTransaction = json_tokener_parse(payload);
  9860. if(!is_error(RemoteStartTransaction))
  9861. {
  9862. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9863. {
  9864. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9865. }
  9866. else
  9867. {
  9868. connectorIdIsNULL = TRUE;
  9869. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9870. {
  9871. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9872. {
  9873. connectorIdIsNULL = FALSE;
  9874. connectorIdInt = (gun_index+1);
  9875. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9876. break;
  9877. }
  9878. }
  9879. }
  9880. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9881. {
  9882. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9883. // Required data
  9884. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9885. // Optional data
  9886. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9887. {
  9888. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9889. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9890. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9891. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9892. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9893. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9894. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9895. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9896. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9897. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9898. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9899. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9900. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9901. {
  9902. 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")));
  9903. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9904. 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"));
  9905. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9906. 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"));
  9907. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9908. 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")));
  9909. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9910. {
  9911. 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++)
  9912. {
  9913. 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"));
  9914. 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"));
  9915. 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)
  9916. 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"));
  9917. }
  9918. }
  9919. }
  9920. }
  9921. else
  9922. {
  9923. chargingProfileIsNULL = TRUE;
  9924. }
  9925. }
  9926. }
  9927. else
  9928. {
  9929. connectorIdIsNULL = TRUE;
  9930. }
  9931. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9932. {
  9933. DEBUG_WARN("Connector id is NULL\n.");
  9934. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9935. goto end;
  9936. }
  9937. /*
  9938. enum _SYSTEM_STATUS
  9939. {
  9940. S_BOOTING = 0,
  9941. S_IDLE, = 1
  9942. S_AUTHORIZING, = 2
  9943. S_REASSIGN_CHECK, = 3
  9944. S_REASSIGN, = 4
  9945. S_PRECHARGE, = 5
  9946. S_PREPARING_FOR_EV, = 6
  9947. S_PREPARING_FOR_EVSE, = 7
  9948. S_CHARGING, = 8
  9949. S_TERMINATING, = 9
  9950. S_COMPLETE, = 10
  9951. S_ALARM, = 11
  9952. S_FAULT = 12
  9953. }
  9954. */
  9955. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9956. {
  9957. //check Transaction active
  9958. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9959. {
  9960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9961. {
  9962. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9963. }
  9964. else
  9965. {
  9966. tempIndex = connectorIdInt -1;
  9967. }
  9968. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9969. {
  9970. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9971. {
  9972. 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))
  9973. {
  9974. //Reserved
  9975. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9976. }
  9977. 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))
  9978. {
  9979. //Reserved
  9980. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9981. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9982. goto end;
  9983. }
  9984. else
  9985. {
  9986. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9987. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9988. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9989. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9990. {
  9991. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9992. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9993. goto end;
  9994. }
  9995. }//END FOR ELSE
  9996. }
  9997. }// END FOR CHAdeMO_QUANTITY
  9998. }
  9999. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10000. {
  10001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10002. {
  10003. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10004. }
  10005. else
  10006. {
  10007. tempIndex = connectorIdInt -1;
  10008. }
  10009. for (int index = 0; index < CCS_QUANTITY; index++)
  10010. {
  10011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10012. {
  10013. 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))
  10014. {
  10015. //Reserved
  10016. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10017. }
  10018. 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))
  10019. {
  10020. //Reserved
  10021. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10022. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10023. goto end;
  10024. }
  10025. else
  10026. {
  10027. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10028. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10029. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10030. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10031. {
  10032. DEBUG_WARN("CCS connector not allow start\n.");
  10033. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10034. goto end;
  10035. }
  10036. }// END FOR ELSE
  10037. }
  10038. }// END FOR CCS_QUANTITY
  10039. }
  10040. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10041. {
  10042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10043. {
  10044. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10045. }
  10046. else
  10047. {
  10048. tempIndex = connectorIdInt -1;
  10049. }
  10050. for (int index = 0; index < GB_QUANTITY; index++)
  10051. {
  10052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10053. {
  10054. 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))
  10055. {
  10056. //Reserved
  10057. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10058. }
  10059. 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))
  10060. {
  10061. //Reserved
  10062. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10063. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10064. goto end;
  10065. }
  10066. else
  10067. {
  10068. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10069. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10070. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10071. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10072. {
  10073. DEBUG_WARN("GB connector not allow start\n.");
  10074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10075. goto end;
  10076. }
  10077. }// END FOR ELSE
  10078. }
  10079. } // END FOR GB_QUANTITY
  10080. }
  10081. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10082. {
  10083. tempIndex = connectorIdInt -1;
  10084. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10085. {
  10086. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10087. {
  10088. 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))
  10089. {
  10090. //Reserved
  10091. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10092. }
  10093. 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))
  10094. {
  10095. //Reserved
  10096. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10097. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10098. goto end;
  10099. }
  10100. else
  10101. {
  10102. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10103. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10104. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10105. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10106. {
  10107. DEBUG_WARN("GB connector not allow start\n.");
  10108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10109. goto end;
  10110. }
  10111. }// END FOR ELSE
  10112. }
  10113. } // END FOR GB_QUANTITY
  10114. }
  10115. else
  10116. {
  10117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10118. {
  10119. tempIndex = 2;
  10120. }
  10121. else
  10122. {
  10123. tempIndex = connectorIdInt -1;
  10124. }
  10125. for (int index = 0; index < AC_QUANTITY; index++)
  10126. {
  10127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10128. {
  10129. 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))
  10130. {
  10131. //Reserved
  10132. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10133. }
  10134. 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))
  10135. {
  10136. //Reserved
  10137. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10138. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10139. goto end;
  10140. }
  10141. else
  10142. {
  10143. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10144. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10145. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10146. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10147. {
  10148. DEBUG_WARN("AC connector not allow start\n.");
  10149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10150. goto end;
  10151. }
  10152. }//END FOR ELSE
  10153. }
  10154. }// END FOR AC_QUANTITY
  10155. }
  10156. if(chargingProfileIsNULL == FALSE)
  10157. {
  10158. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10159. {
  10160. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10161. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10162. //memset idTag
  10163. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10164. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10165. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10167. // Save profile to file
  10168. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10169. system(cmdBuf);
  10170. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10171. fp = fopen(cmdBuf, "w");
  10172. 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));
  10173. fclose(fp);
  10174. }
  10175. else
  10176. {
  10177. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10178. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10179. }
  10180. }
  10181. else
  10182. {
  10183. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10185. //memset idTag
  10186. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10187. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10188. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10189. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10190. }
  10191. }
  10192. else
  10193. {
  10194. DEBUG_WARN("Connector id over\n.");
  10195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10196. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10197. }
  10198. end:
  10199. json_object_put(RemoteStartTransaction);
  10200. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10201. {
  10202. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10203. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10204. }
  10205. //OCPP send RemoteStartConfirmation by first.
  10206. sendRemoteStartConfirmation(uuid, comfirmstr);
  10207. return result;
  10208. }
  10209. int handleRemoteStartRequest(char *uuid, char *payload)
  10210. {
  10211. mtrace();
  10212. int result = PASS;
  10213. int connectorIdInt=-1;
  10214. int tempIndex = 0;
  10215. char comfirmstr[20]={0};
  10216. char cmdBuf[512];
  10217. json_object *RemoteStartTransaction;
  10218. FILE *fp;
  10219. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10220. if(server_pending == TRUE)
  10221. {
  10222. result = FAIL;
  10223. }
  10224. RemoteStartTransaction = json_tokener_parse(payload);
  10225. if(!is_error(RemoteStartTransaction))
  10226. {
  10227. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10228. {
  10229. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10230. }
  10231. else
  10232. {
  10233. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10234. {
  10235. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10236. {
  10237. connectorIdInt = (gun_index+1);
  10238. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10239. break;
  10240. }
  10241. }
  10242. }
  10243. if(connectorIdInt == 0)
  10244. {
  10245. DEBUG_WARN("Connector id shall not equal 0.\n");
  10246. result = FAIL;
  10247. }
  10248. else if(connectorIdInt == -1)
  10249. {
  10250. DEBUG_INFO("Connector id does not specific.\n");
  10251. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10252. {
  10253. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10254. // Required data
  10255. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10256. // Optional data
  10257. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10258. {
  10259. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10260. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10261. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10262. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10263. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10264. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10265. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10266. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10267. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10268. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10269. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10270. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10271. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10272. {
  10273. 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")));
  10274. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10275. 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"));
  10276. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10277. 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"));
  10278. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10279. 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")));
  10280. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10281. {
  10282. 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++)
  10283. {
  10284. 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"));
  10285. 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"));
  10286. 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)
  10287. 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"));
  10288. }
  10289. }
  10290. }
  10291. }
  10292. else
  10293. {
  10294. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10295. }
  10296. }
  10297. }
  10298. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10299. {
  10300. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10301. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10302. // Required data
  10303. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10304. // Optional data
  10305. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10306. {
  10307. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10308. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10309. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10310. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10311. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10312. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10313. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10314. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10315. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10316. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10317. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10318. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10319. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10320. {
  10321. 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")));
  10322. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10323. 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"));
  10324. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10325. 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"));
  10326. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10327. 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")));
  10328. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10329. {
  10330. 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++)
  10331. {
  10332. 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"));
  10333. 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"));
  10334. 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)
  10335. 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"));
  10336. }
  10337. }
  10338. }
  10339. }
  10340. else
  10341. {
  10342. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10343. }
  10344. }
  10345. else
  10346. {
  10347. DEBUG_WARN("Connector id is over maximun value.\n");
  10348. result = FAIL;
  10349. }
  10350. }
  10351. if(result == PASS)
  10352. {
  10353. if(connectorIdInt > 0)
  10354. {
  10355. //check Transaction active
  10356. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10357. {
  10358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10359. {
  10360. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10361. }
  10362. else
  10363. {
  10364. tempIndex = connectorIdInt -1;
  10365. }
  10366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10367. {
  10368. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10369. {
  10370. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10371. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10372. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10373. {
  10374. //Reserved
  10375. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10376. }
  10377. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10379. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10380. {
  10381. //Reserved
  10382. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10383. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10384. goto end;
  10385. }
  10386. else
  10387. {
  10388. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10389. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10390. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10391. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10392. {
  10393. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10394. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10395. goto end;
  10396. }
  10397. }//END FOR ELSE
  10398. }
  10399. }// END FOR CHAdeMO_QUANTITY
  10400. }
  10401. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10402. {
  10403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10404. {
  10405. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10406. }
  10407. else
  10408. {
  10409. tempIndex = connectorIdInt -1;
  10410. }
  10411. for (int index = 0; index < CCS_QUANTITY; index++)
  10412. {
  10413. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10414. {
  10415. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10416. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10417. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10418. {
  10419. //Reserved
  10420. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10421. }
  10422. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10423. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10424. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10425. {
  10426. //Reserved
  10427. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10428. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10429. goto end;
  10430. }
  10431. else
  10432. {
  10433. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10434. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10435. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10436. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10437. {
  10438. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10439. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10440. goto end;
  10441. }
  10442. }// END FOR ELSE
  10443. }
  10444. }// END FOR CCS_QUANTITY
  10445. }
  10446. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10447. {
  10448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10449. {
  10450. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10451. }
  10452. else
  10453. {
  10454. tempIndex = connectorIdInt -1;
  10455. }
  10456. for (int index = 0; index < GB_QUANTITY; index++)
  10457. {
  10458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10459. {
  10460. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10461. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10462. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10463. {
  10464. //Reserved
  10465. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10466. }
  10467. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10468. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10469. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10470. {
  10471. //Reserved
  10472. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10473. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10474. goto end;
  10475. }
  10476. else
  10477. {
  10478. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10479. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10480. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10481. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10482. {
  10483. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10485. goto end;
  10486. }
  10487. }// END FOR ELSE
  10488. }
  10489. } // END FOR GB_QUANTITY
  10490. }
  10491. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10492. {
  10493. tempIndex = connectorIdInt -1;
  10494. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10495. {
  10496. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10497. {
  10498. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10499. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10500. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10501. {
  10502. //Reserved
  10503. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10504. }
  10505. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10506. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10507. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10508. {
  10509. //Reserved
  10510. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10511. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10512. goto end;
  10513. }
  10514. else
  10515. {
  10516. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10517. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10518. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10519. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10520. {
  10521. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10522. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10523. goto end;
  10524. }
  10525. }// END FOR ELSE
  10526. }
  10527. } // END FOR GB_QUANTITY
  10528. }
  10529. else
  10530. {
  10531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10532. {
  10533. tempIndex = 2;
  10534. }
  10535. else
  10536. {
  10537. tempIndex = connectorIdInt -1;
  10538. }
  10539. for (int index = 0; index < AC_QUANTITY; index++)
  10540. {
  10541. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10542. {
  10543. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10544. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10545. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10546. {
  10547. //Reserved
  10548. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10549. }
  10550. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10551. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10552. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10553. {
  10554. //Reserved
  10555. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10556. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10557. goto end;
  10558. }
  10559. else
  10560. {
  10561. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10562. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10563. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10564. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10565. {
  10566. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10567. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10568. goto end;
  10569. }
  10570. }//END FOR ELSE
  10571. }
  10572. }// END FOR AC_QUANTITY
  10573. }
  10574. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10575. {
  10576. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10577. {
  10578. // Save profile to file
  10579. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10580. system(cmdBuf);
  10581. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10582. fp = fopen(cmdBuf, "w");
  10583. 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));
  10584. fclose(fp);
  10585. }
  10586. else
  10587. {
  10588. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10589. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10590. goto end;
  10591. }
  10592. }
  10593. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10594. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10595. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10596. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10597. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10599. }
  10600. else
  10601. {
  10602. uint8_t isHasIdleConnector = FALSE;
  10603. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10604. {
  10605. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10606. {
  10607. isHasIdleConnector = TRUE;
  10608. break;
  10609. }
  10610. }
  10611. if(isHasIdleConnector == TRUE)
  10612. {
  10613. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10614. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10615. {
  10616. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10617. {
  10618. // Save profile to file
  10619. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10620. system(cmdBuf);
  10621. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10622. fp = fopen(cmdBuf, "w");
  10623. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10624. fclose(fp);
  10625. refreshStartTimer(&clientTime.RemoteStartWait);
  10626. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10627. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10628. }
  10629. else
  10630. {
  10631. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10632. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10633. }
  10634. }
  10635. else
  10636. {
  10637. refreshStartTimer(&clientTime.RemoteStartWait);
  10638. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10640. }
  10641. }
  10642. else
  10643. {
  10644. DEBUG_INFO("There is not any connector is idle.\n");
  10645. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10646. }
  10647. }
  10648. }
  10649. else
  10650. {
  10651. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10652. }
  10653. end:
  10654. json_object_put(RemoteStartTransaction);
  10655. sendRemoteStartConfirmation(uuid, comfirmstr);
  10656. return result;
  10657. }
  10658. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10659. {
  10660. mtrace();
  10661. int result = FAIL;
  10662. int match = FALSE;
  10663. int GunNO = 0;
  10664. int tempIndex = 0;
  10665. int transactionIdInt=0;
  10666. int transactionIdIsNULL= TRUE;
  10667. char comfirmstr[20];
  10668. json_object *RemoteStopTransaction;
  10669. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10670. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10671. if(server_pending == TRUE)
  10672. {
  10673. return 0;
  10674. }
  10675. RemoteStopTransaction = json_tokener_parse(payload);
  10676. if(!is_error(RemoteStopTransaction))
  10677. {
  10678. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10679. {
  10680. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10681. transactionIdIsNULL = FALSE;
  10682. }
  10683. }
  10684. json_object_put(RemoteStopTransaction);
  10685. if(transactionIdIsNULL == FALSE)
  10686. {
  10687. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10688. {
  10689. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10690. {
  10691. //check Transaction active
  10692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10693. {
  10694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10695. {
  10696. tempIndex = ((gun_index==2) ? 1: 0);
  10697. }
  10698. else
  10699. {
  10700. tempIndex = gun_index;
  10701. }
  10702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10703. {
  10704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10705. {
  10706. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10707. {
  10708. match = TRUE;
  10709. GunNO = gun_index;
  10710. }
  10711. }
  10712. }// END FOR CHAdeMO_QUANTITY
  10713. }
  10714. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10715. {
  10716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10717. {
  10718. tempIndex = ((gun_index==2) ? 1: 0);
  10719. }
  10720. else
  10721. {
  10722. tempIndex = gun_index;
  10723. }
  10724. for (int index = 0; index < CCS_QUANTITY; index++)
  10725. {
  10726. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10727. {
  10728. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10729. {
  10730. match = TRUE;
  10731. GunNO = gun_index;
  10732. }
  10733. }
  10734. }// END FOR CCS_QUANTITY
  10735. }
  10736. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10737. {
  10738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10739. {
  10740. tempIndex = ((gun_index==2) ? 1: 0);
  10741. }
  10742. else
  10743. {
  10744. tempIndex = gun_index;
  10745. }
  10746. for (int index = 0; index < GB_QUANTITY; index++)
  10747. {
  10748. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10749. {
  10750. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10751. {
  10752. match = TRUE;
  10753. GunNO = gun_index;
  10754. }
  10755. }
  10756. }// END FOR GB_QUANTITY
  10757. }
  10758. else if(gunType[gun_index] == GUN_TYPE_DO)
  10759. {
  10760. tempIndex = gun_index;
  10761. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10762. {
  10763. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10764. {
  10765. 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
  10766. {
  10767. match = TRUE;
  10768. GunNO = gun_index;
  10769. }
  10770. }
  10771. }// END FOR GB_QUANTITY
  10772. }
  10773. else
  10774. {
  10775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10776. {
  10777. tempIndex = 2;
  10778. }
  10779. else
  10780. {
  10781. tempIndex = gun_index;
  10782. }
  10783. for (int index = 0; index < AC_QUANTITY; index++)
  10784. {
  10785. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10786. {
  10787. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10788. {
  10789. match = TRUE;
  10790. GunNO = gun_index;
  10791. }
  10792. }
  10793. }// END FOR CHAdeMO_QUANTITY
  10794. } // END FOR AC ELSE
  10795. }// CHECK IF ResponseTransactionId == transactionIdInt
  10796. }//END FOR
  10797. if( match == TRUE)
  10798. {
  10799. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10800. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10801. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10802. }
  10803. else
  10804. {
  10805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10806. }
  10807. }
  10808. else
  10809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10810. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10811. return result;
  10812. }
  10813. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10814. {
  10815. mtrace();
  10816. int result = FAIL;
  10817. int connectorIdInt=0, reservationIdInt=0;
  10818. int tempIndex = 0;
  10819. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10820. char comfirmstr[20]={0};
  10821. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10822. int c = 0;
  10823. char *loc;
  10824. //char *ptr;
  10825. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10826. strcpy(sstrtemp, stringtrimspace(payload));
  10827. //***(1)connectorId ****/
  10828. c=0;
  10829. loc = strstr(sstrtemp, "connectorId");
  10830. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10831. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10832. {
  10833. sstr[c] = loc[strlen("connectorId")+2+c];
  10834. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10835. c++;
  10836. }
  10837. sstr[c] = '\0';
  10838. connectorIdInt = atoi(sstr);
  10839. //***(2)expiryDate ****/
  10840. loc = strstr(sstrtemp, "expiryDate");
  10841. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10842. c = 0;
  10843. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10844. {
  10845. sstr[c] = loc[3+strlen("expiryDate")+c];
  10846. c++;
  10847. }
  10848. sstr[c] = '\0';
  10849. strcpy(expiryDatestr, sstr);
  10850. //***(3)idTag ****/
  10851. loc = strstr(sstrtemp, "idTag");
  10852. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10853. c = 0;
  10854. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10855. {
  10856. sstr[c] = loc[3+strlen("idTag")+c];
  10857. c++;
  10858. }
  10859. sstr[c] = '\0';
  10860. strcpy(idTagstr, sstr);
  10861. //***(4)parentIdTag ****/
  10862. loc = strstr(sstrtemp, "parentIdTag");
  10863. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10864. c = 0;
  10865. if(loc == NULL)
  10866. {
  10867. strcpy(parentIdTagstr, "");
  10868. }
  10869. else
  10870. {
  10871. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10872. {
  10873. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10874. c++;
  10875. }
  10876. sstr[c] = '\0';
  10877. strcpy(parentIdTagstr, sstr);
  10878. }
  10879. //***(5)reservationId ****/
  10880. c=0;
  10881. loc = strstr(sstrtemp, "reservationId");
  10882. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10883. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10884. {
  10885. sstr[c] = loc[strlen("reservationId")+2+c];
  10886. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10887. c++;
  10888. }
  10889. sstr[c] = '\0';
  10890. reservationIdInt = atoi(sstr);
  10891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10892. /*
  10893. enum SYSTEM_STATUS
  10894. {
  10895. SYS_MODE_BOOTING = 0,
  10896. SYS_MODE_IDLE = 1,
  10897. SYS_MODE_AUTHORIZING = 2,
  10898. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10899. SYS_MODE_REASSIGN = 4,
  10900. SYS_MODE_PREPARING = 5,
  10901. SYS_MODE_PREPARE_FOR_EV = 6,
  10902. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10903. SYS_MODE_CHARGING = 8,
  10904. SYS_MODE_TERMINATING = 9,
  10905. SYS_MODE_COMPLETE = 10,
  10906. SYS_MODE_ALARM = 11,
  10907. SYS_MODE_FAULT = 12,
  10908. SYS_MODE_RESERVATION = 13,
  10909. SYS_MODE_BOOKING = 14,
  10910. SYS_MODE_MAINTAIN = 15,
  10911. SYS_MODE_DEBUG = 16,
  10912. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10913. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10914. SYS_MODE_UPDATE = 19
  10915. };
  10916. */
  10917. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10918. {
  10919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10920. goto end;
  10921. }
  10922. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10923. {
  10924. //check Transaction active
  10925. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10926. {
  10927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10928. {
  10929. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10930. }
  10931. else
  10932. {
  10933. tempIndex = connectorIdInt -1;
  10934. }
  10935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10936. {
  10937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10938. {
  10939. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10940. {
  10941. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10942. {
  10943. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10944. {
  10945. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10947. }
  10948. 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'))
  10949. {
  10950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10951. }
  10952. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10953. {
  10954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10955. }
  10956. else
  10957. {
  10958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10959. }
  10960. }
  10961. 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
  10962. {
  10963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10964. }
  10965. }
  10966. else
  10967. {
  10968. //replace reservation
  10969. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10971. }
  10972. }
  10973. } // END FOR CHAdeMO_QUANTITY
  10974. }
  10975. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10976. {
  10977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10978. {
  10979. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10980. }
  10981. else
  10982. {
  10983. tempIndex = connectorIdInt -1;
  10984. }
  10985. for (int index = 0; index < CCS_QUANTITY; index++)
  10986. {
  10987. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10988. {
  10989. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10990. {
  10991. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10992. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10993. {
  10994. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10995. {
  10996. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10998. }
  10999. 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'))
  11000. {
  11001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11002. }
  11003. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11004. {
  11005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11006. }
  11007. else
  11008. {
  11009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11010. }
  11011. }
  11012. 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
  11013. {
  11014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11015. }
  11016. }
  11017. else
  11018. {
  11019. //replace reservation
  11020. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11022. }
  11023. }
  11024. } // END FOR CCS_QUANTITY
  11025. }
  11026. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11027. {
  11028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11029. {
  11030. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11031. }
  11032. else
  11033. {
  11034. tempIndex = connectorIdInt -1;
  11035. }
  11036. for (int index = 0; index < GB_QUANTITY; index++)
  11037. {
  11038. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11039. {
  11040. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11041. {
  11042. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11043. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11044. {
  11045. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11046. {
  11047. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11049. }
  11050. 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'))
  11051. {
  11052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11053. }
  11054. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11055. {
  11056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11057. }
  11058. else
  11059. {
  11060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11061. }
  11062. }
  11063. 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
  11064. {
  11065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11066. }
  11067. }
  11068. else
  11069. {
  11070. //replace reservation
  11071. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11073. }
  11074. }
  11075. }// END FOR GB_QUANTITY
  11076. }
  11077. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11078. {
  11079. tempIndex = connectorIdInt -1;
  11080. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11081. {
  11082. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11083. {
  11084. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11085. {
  11086. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11087. 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
  11088. {
  11089. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11090. {
  11091. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11092. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11093. }
  11094. 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'))
  11095. {
  11096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11097. }
  11098. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11099. {
  11100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11101. }
  11102. else
  11103. {
  11104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11105. }
  11106. }
  11107. 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
  11108. {
  11109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11110. }
  11111. }
  11112. else
  11113. {
  11114. //replace reservation
  11115. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11117. }
  11118. }
  11119. }// END FOR GB_QUANTITY
  11120. }
  11121. else
  11122. {
  11123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11124. {
  11125. tempIndex = 2;
  11126. }
  11127. else
  11128. {
  11129. tempIndex = (connectorIdInt -1);
  11130. }
  11131. for (int index = 0; index < AC_QUANTITY; index++)
  11132. {
  11133. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11134. {
  11135. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11136. {
  11137. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11138. {
  11139. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11140. {
  11141. 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))
  11142. {
  11143. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11144. }
  11145. else
  11146. {
  11147. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11149. }
  11150. }
  11151. 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'))
  11152. {
  11153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11154. }
  11155. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11156. {
  11157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11158. }
  11159. else
  11160. {
  11161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11162. }
  11163. }
  11164. 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
  11165. {
  11166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11167. }
  11168. }
  11169. else
  11170. {
  11171. //replace reservation
  11172. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11174. }
  11175. }
  11176. } // END FOR AC_QUANTITY
  11177. }
  11178. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11179. }
  11180. else if(connectorIdInt == 0)
  11181. {
  11182. //check Transaction active
  11183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11184. {
  11185. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11186. {
  11187. 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'))
  11188. {
  11189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11190. goto end;
  11191. }
  11192. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11193. {
  11194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11195. goto end;
  11196. }
  11197. 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
  11198. {
  11199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11200. goto end;
  11201. }
  11202. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11203. {
  11204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11205. goto end;
  11206. }
  11207. }
  11208. }// END FOR CHAdeMO_QUANTITY
  11209. for (int index = 0; index < CCS_QUANTITY; index++)
  11210. {
  11211. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11212. {
  11213. 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'))
  11214. {
  11215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11216. goto end;
  11217. }
  11218. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11219. {
  11220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11221. goto end;
  11222. }
  11223. 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
  11224. {
  11225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11226. goto end;
  11227. }
  11228. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11229. {
  11230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11231. goto end;
  11232. }
  11233. }
  11234. } // END FOR CCS_QUANTITY
  11235. for (int index = 0; index < GB_QUANTITY; index++)
  11236. {
  11237. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11238. {
  11239. 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'))
  11240. {
  11241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11242. goto end;
  11243. }
  11244. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11245. {
  11246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11247. goto end;
  11248. }
  11249. 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
  11250. {
  11251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11252. goto end;
  11253. }
  11254. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11255. {
  11256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11257. goto end;
  11258. }
  11259. }
  11260. } // END FOR GB_QUANTITY
  11261. for (int index = 0; index < AC_QUANTITY; index++)
  11262. {
  11263. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11264. {
  11265. 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'))
  11266. {
  11267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11268. goto end;
  11269. }
  11270. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11271. {
  11272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11273. goto end;
  11274. }
  11275. 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
  11276. {
  11277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11278. goto end;
  11279. }
  11280. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11281. {
  11282. 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))
  11283. {
  11284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11285. goto end;
  11286. }
  11287. }
  11288. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11289. {
  11290. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11291. goto end;
  11292. }
  11293. }
  11294. }// END FOR AC_QUANTITY
  11295. //The connectorId is 0
  11296. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11298. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11299. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11300. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11301. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11302. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11303. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11304. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11305. result = TRUE;
  11306. return result;
  11307. }
  11308. else
  11309. {
  11310. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11311. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11312. }
  11313. if(strcmp(comfirmstr,"Accepted") == 0)
  11314. {
  11315. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11316. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11317. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11318. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11319. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11320. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11321. result = TRUE;
  11322. return result;
  11323. }
  11324. end:
  11325. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11326. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11327. return result;
  11328. }
  11329. int handleResetRequest(char *uuid, char *payload)
  11330. {
  11331. mtrace();
  11332. int result = FAIL;
  11333. char sstr[10]={0},sstrtemp[30]={ 0 };
  11334. char typestr[10]={0};
  11335. char comfirmstr[20]={0};
  11336. int c = 0;
  11337. char *loc;
  11338. DEBUG_INFO("handleResetRequest...\n");
  11339. strcpy(sstrtemp, stringtrimspace(payload));
  11340. loc = strstr(sstrtemp, "type");
  11341. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11342. c = 0;
  11343. while (loc[3+strlen("type")+c] != '\"')
  11344. {
  11345. sstr[c] = loc[3+strlen("type")+c];
  11346. c++;
  11347. }
  11348. sstr[c] = '\0';
  11349. strcpy(typestr,sstr);
  11350. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11351. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11352. {
  11353. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11354. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11355. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11356. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11357. }
  11358. else
  11359. {
  11360. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11361. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11362. result = PASS;
  11363. }
  11364. sendResetConfirmation(uuid, comfirmstr);
  11365. return result;
  11366. }
  11367. int handleSendLocalListRequest(char *uuid, char *payload)
  11368. {
  11369. mtrace();
  11370. int result = FAIL;
  11371. char comfirmstr[20];
  11372. int checkState_Faulted = FALSE;
  11373. json_object *SendLocalList;
  11374. DEBUG_INFO("handleSendLocalListRequest...\n");
  11375. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11376. {
  11377. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11378. goto end;
  11379. }
  11380. //check Charge Point state
  11381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11382. {
  11383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11384. {
  11385. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11386. }
  11387. }
  11388. for (int index = 0; index < CCS_QUANTITY; index++)
  11389. {
  11390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11391. {
  11392. checkState_Faulted = TRUE; //OCPP Status
  11393. }
  11394. }
  11395. for (int index = 0; index < GB_QUANTITY; index++)
  11396. {
  11397. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11398. {
  11399. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11400. }
  11401. }
  11402. //check Charge Point state
  11403. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11404. {
  11405. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11406. {
  11407. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11408. }
  11409. }
  11410. //check Charge Point state
  11411. for (int index = 0; index < AC_QUANTITY; index++)
  11412. {
  11413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11414. {
  11415. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11416. }
  11417. }
  11418. if(checkState_Faulted == TRUE)
  11419. {
  11420. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11421. goto end;
  11422. }
  11423. // Parsing payload
  11424. SendLocalList = json_tokener_parse(payload);
  11425. if(!is_error(SendLocalList))
  11426. {
  11427. // Required data
  11428. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11429. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11430. // Optional data
  11431. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11432. {
  11433. //Check UpdateType
  11434. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11435. {
  11436. //Local list full update
  11437. DEBUG_INFO("Local list full update.\n");
  11438. OCPP_getListVerion();
  11439. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11440. {
  11441. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11442. goto end;
  11443. }
  11444. OCPP_cleanLocalList();
  11445. }
  11446. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11447. {
  11448. //Local list different update
  11449. DEBUG_INFO("Local list different update.\n");
  11450. OCPP_getListVerion();
  11451. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11452. {
  11453. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11454. goto end;
  11455. }
  11456. }
  11457. else
  11458. {
  11459. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11460. goto end;
  11461. }
  11462. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11463. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11464. {
  11465. 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")));
  11466. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11467. {
  11468. 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")));
  11469. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11470. 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")));
  11471. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11472. 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")));
  11473. }
  11474. // Add to db
  11475. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11476. {
  11477. //Local list full update
  11478. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11479. idx,
  11480. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11481. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11482. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11483. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11484. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11485. // update list
  11486. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11487. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11488. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11489. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11490. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11491. }
  11492. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11493. {
  11494. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11495. idx,
  11496. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11497. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11498. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11499. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11500. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11501. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11502. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11503. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11504. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11505. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11506. }
  11507. }
  11508. }
  11509. else
  11510. {
  11511. //Check UpdateType
  11512. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11513. {
  11514. //Local list full update
  11515. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11516. OCPP_cleanLocalList();
  11517. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11518. goto end;
  11519. }
  11520. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11521. {
  11522. //Local list different update
  11523. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11524. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11525. goto end;
  11526. }
  11527. }
  11528. result = PASS;
  11529. }
  11530. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11531. end:
  11532. json_object_put(SendLocalList);
  11533. sendSendLocalListConfirmation(uuid, comfirmstr);
  11534. return result;
  11535. }
  11536. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11537. {
  11538. mtrace();
  11539. int result = FAIL;
  11540. struct StructSetChargingProfile SetProfileReq = {0};
  11541. int tempchargingProfileIdInt;
  11542. int tempstackLevelInt;
  11543. int chargingSchedulePeriodCount = 0;
  11544. char comfirmstr[20]={0};
  11545. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11546. char rmFileCmd[128]={0};
  11547. int profileQuantity = 0;
  11548. int isReplaceable = FALSE;
  11549. json_object *SetChargingProfile;
  11550. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11551. SetChargingProfile = json_tokener_parse(payload);
  11552. if(!is_error(SetChargingProfile))
  11553. {
  11554. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11555. {
  11556. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11557. }
  11558. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11559. {
  11560. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11561. {
  11562. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11563. }
  11564. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11565. {
  11566. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11567. }
  11568. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11569. {
  11570. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11571. }
  11572. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11573. {
  11574. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11575. }
  11576. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11577. {
  11578. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11579. }
  11580. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11581. {
  11582. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11583. }
  11584. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11585. {
  11586. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11587. }
  11588. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11589. {
  11590. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11591. }
  11592. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11593. {
  11594. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11595. {
  11596. 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")));
  11597. }
  11598. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11599. {
  11600. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11601. }
  11602. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11603. {
  11604. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11605. }
  11606. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11607. {
  11608. 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")));
  11609. }
  11610. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11611. {
  11612. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11613. if(chargingSchedulePeriodCount <= 10)
  11614. {
  11615. 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++)
  11616. {
  11617. 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)
  11618. {
  11619. 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"));
  11620. }
  11621. 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)
  11622. {
  11623. 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"));
  11624. }
  11625. 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)
  11626. {
  11627. 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"));
  11628. }
  11629. }
  11630. }
  11631. }
  11632. }
  11633. }
  11634. }
  11635. // Profile periods quantity check
  11636. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11637. {
  11638. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11639. goto end;
  11640. }
  11641. // Check invalid limit
  11642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11643. {
  11644. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11645. {
  11646. 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)))) ||
  11647. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11648. {
  11649. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11650. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11651. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11652. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11653. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11654. goto end;
  11655. }
  11656. }
  11657. }
  11658. else
  11659. {
  11660. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11661. {
  11662. 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))
  11663. {
  11664. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11665. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11666. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11667. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11668. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11669. goto end;
  11670. }
  11671. }
  11672. }
  11673. // Profile purpose info check
  11674. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11675. {
  11676. FILE *fp;
  11677. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11678. if(SetProfileReq.ConnectorId != 0)
  11679. {
  11680. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11681. goto end;
  11682. }
  11683. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11684. if (!fp)
  11685. {
  11686. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11687. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11688. }
  11689. else
  11690. {
  11691. char *line = NULL;
  11692. size_t len = 0;
  11693. while(getline(&line, &len, fp) != -1)
  11694. {
  11695. json_object *obj = NULL;
  11696. obj = json_tokener_parse(line);
  11697. if(is_error(obj))
  11698. {
  11699. DEBUG_ERROR("Parse txProfile from file error.\n");
  11700. }
  11701. else
  11702. {
  11703. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11704. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11705. {
  11706. profileQuantity += 1;
  11707. }
  11708. else
  11709. isReplaceable = TRUE;
  11710. }
  11711. }
  11712. }
  11713. fclose(fp);
  11714. }
  11715. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11716. {
  11717. FILE *fp;
  11718. char filename[128]={0};
  11719. int tmpProfileQuantity;
  11720. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11721. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11722. {
  11723. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11724. goto end;
  11725. }
  11726. if(SetProfileReq.ConnectorId == 0)
  11727. {
  11728. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11729. {
  11730. tmpProfileQuantity = 0;
  11731. memset(filename, 0, ARRAY_SIZE(filename));
  11732. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11733. fp = fopen(filename, "r");
  11734. if (!fp)
  11735. {
  11736. DEBUG_INFO("%s does not create.\n", filename);
  11737. fp = fopen(filename, "w+");
  11738. }
  11739. else
  11740. {
  11741. char *line = NULL;
  11742. size_t len = 0;
  11743. while(getline(&line, &len, fp) != -1)
  11744. {
  11745. json_object *obj = NULL;
  11746. obj = json_tokener_parse(line);
  11747. if(is_error(obj))
  11748. {
  11749. DEBUG_ERROR("Parse txProfile from file error.\n");
  11750. }
  11751. else
  11752. {
  11753. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11754. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11755. {
  11756. tmpProfileQuantity += 1;
  11757. }
  11758. else
  11759. isReplaceable = TRUE;
  11760. }
  11761. }
  11762. }
  11763. fclose(fp);
  11764. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11765. }
  11766. }
  11767. else
  11768. {
  11769. memset(filename, 0, ARRAY_SIZE(filename));
  11770. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11771. fp = fopen(filename, "r");
  11772. if (!fp)
  11773. {
  11774. DEBUG_INFO("%s does not create.\n", filename);
  11775. fp = fopen(filename, "w+");
  11776. }
  11777. else
  11778. {
  11779. char *line = NULL;
  11780. size_t len = 0;
  11781. while(getline(&line, &len, fp) != -1)
  11782. {
  11783. json_object *obj = NULL;
  11784. obj = json_tokener_parse(line);
  11785. if(is_error(obj))
  11786. {
  11787. DEBUG_ERROR("Parse txProfile from file error.\n");
  11788. }
  11789. else
  11790. {
  11791. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11792. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11793. {
  11794. profileQuantity += 1;
  11795. }
  11796. else
  11797. isReplaceable = TRUE;
  11798. }
  11799. }
  11800. }
  11801. fclose(fp);
  11802. }
  11803. }
  11804. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11805. {
  11806. int isMatchTransactiodId= FALSE;
  11807. FILE *fp;
  11808. char filename[128]={0};
  11809. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11810. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11811. if(SetProfileReq.ConnectorId == 0)
  11812. {
  11813. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11814. goto end;
  11815. }
  11816. int tempIndex = 0;
  11817. //check Transaction active
  11818. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11819. {
  11820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11821. {
  11822. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11823. }
  11824. else
  11825. {
  11826. tempIndex = SetProfileReq.ConnectorId -1;
  11827. }
  11828. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11829. {
  11830. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11831. {
  11832. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11833. {
  11834. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11835. {
  11836. isMatchTransactiodId = TRUE;
  11837. break;
  11838. }
  11839. }
  11840. }
  11841. }
  11842. }
  11843. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11844. {
  11845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11846. {
  11847. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11848. }
  11849. else
  11850. {
  11851. tempIndex = SetProfileReq.ConnectorId -1;
  11852. }
  11853. for (int index = 0; index < CCS_QUANTITY; index++)
  11854. {
  11855. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11856. {
  11857. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11858. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11859. {
  11860. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11861. {
  11862. isMatchTransactiodId = TRUE;
  11863. break;
  11864. }
  11865. }
  11866. }
  11867. }
  11868. }
  11869. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11870. {
  11871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11872. {
  11873. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11874. }
  11875. else
  11876. {
  11877. tempIndex = SetProfileReq.ConnectorId -1;
  11878. }
  11879. for (int index = 0; index < GB_QUANTITY; index++)
  11880. {
  11881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11882. {
  11883. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11884. {
  11885. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11886. {
  11887. isMatchTransactiodId = TRUE;
  11888. break;
  11889. }
  11890. }
  11891. }
  11892. }
  11893. }
  11894. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11895. {
  11896. tempIndex = SetProfileReq.ConnectorId -1;
  11897. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11898. {
  11899. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11900. {
  11901. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11902. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11903. {
  11904. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11905. {
  11906. isMatchTransactiodId = TRUE;
  11907. break;
  11908. }
  11909. }
  11910. }
  11911. }
  11912. }
  11913. else
  11914. {
  11915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11916. {
  11917. tempIndex = 2;
  11918. }
  11919. else
  11920. {
  11921. tempIndex = (SetProfileReq.ConnectorId -1);
  11922. }
  11923. for (int index = 0; index < AC_QUANTITY; index++)
  11924. {
  11925. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11926. {
  11927. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11928. {
  11929. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11930. {
  11931. isMatchTransactiodId = TRUE;
  11932. break;
  11933. }
  11934. }
  11935. }
  11936. }
  11937. }
  11938. //check Transaction active
  11939. if(isMatchTransactiodId == FALSE)
  11940. {
  11941. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11942. goto end;
  11943. }
  11944. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11945. {
  11946. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11947. goto end;
  11948. }
  11949. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11950. fp = fopen(filename, "r");
  11951. if (!fp)
  11952. {
  11953. DEBUG_INFO("%s does not create.\n", filename);
  11954. fp = fopen(filename, "w+");
  11955. }
  11956. else
  11957. {
  11958. char *line = NULL;
  11959. size_t len = 0;
  11960. while(getline(&line, &len, fp) != -1)
  11961. {
  11962. json_object *obj = NULL;
  11963. obj = json_tokener_parse(line);
  11964. if(is_error(obj))
  11965. {
  11966. DEBUG_ERROR("Parse txProfile from file error.\n");
  11967. }
  11968. else
  11969. {
  11970. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11971. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11972. {
  11973. profileQuantity += 1;
  11974. }
  11975. else
  11976. isReplaceable = TRUE;
  11977. }
  11978. }
  11979. }
  11980. fclose(fp);
  11981. }
  11982. // Check ChargeProfileMaxStackLevel
  11983. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11984. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11985. {
  11986. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11987. goto end;
  11988. }
  11989. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11990. {
  11991. FILE *fp;
  11992. char dataLine[4096]={0};
  11993. char fnametemp[128]={0};
  11994. int tmpProfileQuantity;
  11995. //Check ChargePointMaxProfile.json exit
  11996. profileQuantity = 0;
  11997. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11998. {
  11999. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12000. //Check Charging Profile Count
  12001. tmpProfileQuantity = 0;
  12002. while(fscanf(fp, "%s", dataLine) != EOF)
  12003. {
  12004. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12005. {
  12006. profileQuantity += 1;
  12007. tmpProfileQuantity += 1;
  12008. }
  12009. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12010. }
  12011. fclose(fp);
  12012. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12013. }
  12014. //Check TxDefaultProfile_%d.json
  12015. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12016. {
  12017. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12018. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12019. if((access(fnametemp,F_OK))!=-1)
  12020. {
  12021. fp = fopen(fnametemp, "r");
  12022. //Check Charging Profile Count
  12023. tmpProfileQuantity = 0;
  12024. while(fscanf(fp, "%s", dataLine) != EOF)
  12025. {
  12026. //DEBUG_INFO("word=%s\n",word);
  12027. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12028. {
  12029. profileQuantity += 1;
  12030. tmpProfileQuantity += 1;
  12031. }
  12032. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12033. }
  12034. fclose(fp);
  12035. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12036. }
  12037. }
  12038. //Check TxProfile_%d.json
  12039. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12040. {
  12041. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12042. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12043. if((access(fnametemp,F_OK))!=-1)
  12044. {
  12045. fp = fopen(fnametemp, "r");
  12046. //Check Charging Profile Count
  12047. tmpProfileQuantity = 0;
  12048. while(fscanf(fp, "%s", dataLine) != EOF)
  12049. {
  12050. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12051. {
  12052. profileQuantity += 1;
  12053. tmpProfileQuantity += 1;
  12054. }
  12055. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12056. }
  12057. fclose(fp);
  12058. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12059. }
  12060. }
  12061. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12062. if((profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12063. {
  12064. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12065. goto end;
  12066. }
  12067. }
  12068. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12069. //**********************************Write to File********************************************************/
  12070. {
  12071. FILE *infile;
  12072. FILE *outfile;
  12073. char dataLine[4096]={0};
  12074. char filename[128]={0};
  12075. int chkChar=0;
  12076. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12077. {
  12078. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12079. {
  12080. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12081. }
  12082. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12083. {
  12084. if(SetProfileReq.ConnectorId==0)
  12085. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12086. else
  12087. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12088. }
  12089. else
  12090. {
  12091. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12092. }
  12093. infile = fopen (filename, "r");
  12094. outfile = fopen (tempfile, "w");
  12095. chkChar = fgetc(infile);
  12096. rewind(infile);
  12097. if(chkChar == EOF)
  12098. {
  12099. // Profile is empty
  12100. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12101. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12102. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12103. fclose(infile);
  12104. fclose(outfile);
  12105. sprintf(rmFileCmd,"rm -f %s",filename);
  12106. system(rmFileCmd);
  12107. rename(tempfile, filename);
  12108. }
  12109. else
  12110. {
  12111. // Profile is not empty
  12112. int ChargingProfileAdded = FALSE;
  12113. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12114. {
  12115. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12116. json_object *tmpChargingProfile;
  12117. tmpChargingProfile = json_tokener_parse(dataLine);
  12118. if(!is_error(SetChargingProfile))
  12119. {
  12120. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12121. {
  12122. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12123. {
  12124. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12125. }
  12126. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12127. {
  12128. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12129. }
  12130. }
  12131. }
  12132. json_object_put(tmpChargingProfile);
  12133. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12134. {
  12135. if(ChargingProfileAdded == FALSE)
  12136. {
  12137. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12138. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12139. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12140. ChargingProfileAdded = TRUE;
  12141. }
  12142. }
  12143. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12144. {
  12145. if(ChargingProfileAdded == FALSE)
  12146. {
  12147. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12148. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12149. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12150. ChargingProfileAdded = TRUE;
  12151. }
  12152. }
  12153. else
  12154. {
  12155. fprintf(outfile,"%s\n",dataLine);
  12156. if(ChargingProfileAdded == FALSE)
  12157. {
  12158. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12159. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12160. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12161. ChargingProfileAdded = TRUE;
  12162. }
  12163. }
  12164. } // end of while loop
  12165. fclose(infile);
  12166. fclose(outfile);
  12167. sprintf(rmFileCmd,"rm -f %s",filename);
  12168. system(rmFileCmd);
  12169. rename(tempfile, filename);
  12170. }
  12171. }
  12172. sleep(1);
  12173. result = TRUE;
  12174. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12175. }
  12176. end:
  12177. json_object_put(SetChargingProfile);
  12178. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12179. {
  12180. if(SetProfileReq.ConnectorId == 0)
  12181. {
  12182. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12183. {
  12184. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12185. }
  12186. }
  12187. else
  12188. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12189. }
  12190. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12191. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12192. return result;
  12193. }
  12194. int handleTriggerMessageRequest(char *uuid, char *payload)
  12195. {
  12196. mtrace();
  12197. int result = FAIL;
  12198. int connectorIdIsNULL = FALSE;
  12199. int connectorIdInt =0;
  12200. char sstr[40]={0},sstrtemp[100]={ 0 };
  12201. char requestedMessagestr[40]={0};
  12202. char comfirmstr[20]={0};
  12203. int c = 0;
  12204. char *loc;
  12205. DEBUG_INFO("handleTriggerMessageRequest\n");
  12206. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12207. strcpy(sstrtemp, stringtrimspace(payload));
  12208. c = 0;
  12209. loc = strstr(sstrtemp, "requestedMessage");
  12210. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12211. {
  12212. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12213. c++;
  12214. }
  12215. sstr[c] = '\0';
  12216. strcpy(requestedMessagestr, sstr);
  12217. c = 0;
  12218. loc = strstr(sstrtemp, "connectorId");
  12219. if(loc == NULL)
  12220. {
  12221. connectorIdIsNULL = TRUE;
  12222. }
  12223. else
  12224. {
  12225. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12226. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12227. {
  12228. sstr[c] = loc[strlen("connectorId")+2+c];
  12229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12230. c++;
  12231. }
  12232. sstr[c] = '\0';
  12233. connectorIdInt = atoi(sstr);
  12234. }
  12235. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12236. {
  12237. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12238. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12239. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12240. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12241. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12242. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12243. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12244. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12245. {
  12246. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12247. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12248. return TRUE;
  12249. }
  12250. else
  12251. {
  12252. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12253. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12254. }
  12255. }
  12256. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12257. {
  12258. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12259. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12260. return TRUE;
  12261. }
  12262. //==========================
  12263. // Trigger message
  12264. //==========================
  12265. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12266. {
  12267. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12268. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12269. {
  12270. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12271. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12272. }
  12273. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12274. }
  12275. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12276. {
  12277. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12278. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12279. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12280. }
  12281. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12282. {
  12283. //sendBootNotificationRequest();
  12284. server_sign = FALSE;
  12285. }
  12286. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12287. {
  12288. refreshStartTimer(&clientTime.Heartbeat);
  12289. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12290. }
  12291. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12292. {
  12293. if(connectorIdIsNULL == FALSE)
  12294. {
  12295. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12296. {
  12297. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12298. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12299. }
  12300. }
  12301. else
  12302. {
  12303. for(int idx=0;idx< gunTotalNumber;idx++)
  12304. {
  12305. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12306. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12307. }
  12308. }
  12309. }
  12310. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12311. {
  12312. if(connectorIdIsNULL == FALSE)
  12313. {
  12314. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12315. {
  12316. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12317. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12318. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12319. }
  12320. }
  12321. else
  12322. {
  12323. for(int idx=0;idx< gunTotalNumber;idx++)
  12324. {
  12325. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12326. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12327. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12328. }
  12329. }
  12330. }
  12331. return result;
  12332. }
  12333. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12334. {
  12335. mtrace();
  12336. int result = FAIL;
  12337. int connectorIdInt =0;
  12338. char comfirmstr[20]={0};
  12339. int tempIndex = 0;
  12340. json_object *UnlockConnector;
  12341. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12342. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12343. UnlockConnector = json_tokener_parse(payload);
  12344. if(!is_error(UnlockConnector))
  12345. {
  12346. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12347. {
  12348. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12349. }
  12350. }
  12351. json_object_put(UnlockConnector);
  12352. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12353. if(gunTotalNumber == 0)
  12354. {
  12355. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12356. goto end;
  12357. }
  12358. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12359. {
  12360. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12361. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12362. goto end;
  12363. }
  12364. else
  12365. {
  12366. //check Transaction active
  12367. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12368. {
  12369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12370. {
  12371. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12372. }
  12373. else
  12374. {
  12375. tempIndex = connectorIdInt -1;
  12376. }
  12377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12378. {
  12379. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12380. {
  12381. //stop Transaction
  12382. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12383. }
  12384. }
  12385. }
  12386. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12387. {
  12388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12389. {
  12390. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12391. }
  12392. else
  12393. {
  12394. tempIndex = connectorIdInt -1;
  12395. }
  12396. for (int index = 0; index < CCS_QUANTITY; index++)
  12397. {
  12398. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12399. {
  12400. //stop Transaction
  12401. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12402. }
  12403. }
  12404. }
  12405. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12406. {
  12407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12408. {
  12409. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12410. }
  12411. else
  12412. {
  12413. tempIndex = connectorIdInt -1;
  12414. }
  12415. for (int index = 0; index < GB_QUANTITY; index++)
  12416. {
  12417. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12418. {
  12419. //stop Transaction
  12420. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12421. }
  12422. }
  12423. }
  12424. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12425. {
  12426. tempIndex = connectorIdInt -1;
  12427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12428. {
  12429. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12430. {
  12431. //stop Transaction
  12432. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12433. }
  12434. }
  12435. }
  12436. else
  12437. {
  12438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12439. {
  12440. tempIndex = 2;
  12441. }
  12442. else
  12443. {
  12444. tempIndex = connectorIdInt-1;
  12445. }
  12446. for (int index = 0; index < AC_QUANTITY; index++)
  12447. {
  12448. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12449. {
  12450. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12451. }
  12452. }
  12453. }
  12454. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12455. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12456. result = TRUE;
  12457. return result;
  12458. }
  12459. end:
  12460. //json_object_put(obj); --- remove temporally
  12461. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12462. return result;
  12463. }
  12464. static char UpdateFirmwarepayloadData[300]={0};
  12465. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12466. {
  12467. mtrace();
  12468. int result = FAIL;
  12469. pthread_t t;
  12470. sendUpdateFirmwareConfirmation(uuid);
  12471. memset(UpdateFirmwarepayloadData, 0, 300);
  12472. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12473. if(!interLock.isUpdateFirmwareGoing)
  12474. {
  12475. interLock.isUpdateFirmwareGoing = 1;
  12476. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12477. sleep(1);
  12478. }
  12479. else
  12480. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12481. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12482. return result;
  12483. }
  12484. void *UpdateFirmwareProcess(void *data)
  12485. {
  12486. pthread_detach(pthread_self());
  12487. mtrace();
  12488. int retriesInt =0, retryIntervalInt=0;
  12489. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12490. int port=0;
  12491. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12492. int isSuccess = 0;
  12493. char ftpbuf[512];
  12494. char temp[100];
  12495. char * pch;
  12496. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12497. json_object *UpdateFirmware;
  12498. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12499. if(!is_error(UpdateFirmware))
  12500. {
  12501. // Required data
  12502. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12503. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12504. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12505. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12506. // Optional data
  12507. if(json_object_object_get(UpdateFirmware, "retries"))
  12508. {
  12509. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12510. }
  12511. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12512. {
  12513. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12514. }
  12515. }
  12516. json_object_put(UpdateFirmware);
  12517. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12518. memset(path, 0, ARRAY_SIZE(path));
  12519. // Wait retrieveData
  12520. if(strlen(retrieveDatestr) > 10)
  12521. {
  12522. do
  12523. {
  12524. sleep(1);
  12525. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12526. }
  12527. // Ready to download
  12528. system("rm -f /mnt/*");
  12529. if(strncmp(locationstr,"http", 4) == 0)
  12530. {
  12531. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12532. sprintf(ftppath,"/%s", path);
  12533. DEBUG_INFO("locationstr: %s\n", locationstr);
  12534. DEBUG_INFO("protocol: %s\n",protocol);
  12535. DEBUG_INFO("host: %s\n",host);
  12536. DEBUG_INFO("path: %s\n",path);
  12537. DEBUG_INFO("ftppath: %s\n",ftppath);
  12538. int ftppathlen=strlen(ftppath);
  12539. int i=1;
  12540. char filenametemp[50];
  12541. while(i < ftppathlen)
  12542. {
  12543. int len=ftppathlen-i;
  12544. if(ftppath[len]== 47) // '/' ascll code: 47
  12545. {
  12546. DEBUG_INFO("compare '/' all right\n");
  12547. break;
  12548. }
  12549. i=i+1;
  12550. }
  12551. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12552. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12553. filenametemp[i+1] = 0;
  12554. do
  12555. {
  12556. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12557. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12558. sleep(1);
  12559. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12560. if(!isSuccess)
  12561. {
  12562. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12563. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12564. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12565. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12566. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12567. }
  12568. else
  12569. {
  12570. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12571. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12572. }
  12573. retriesInt--;
  12574. }while((isSuccess == 0)&&(retriesInt >= 0));
  12575. }
  12576. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12577. {
  12578. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12579. memset(temp, 0, ARRAY_SIZE(temp));
  12580. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12581. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12582. int ftppathlen=strlen(ftpbuf);
  12583. int i=1;
  12584. char filenametemp[50];
  12585. while(i < ftppathlen)
  12586. {
  12587. int len=ftppathlen-i;
  12588. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12589. {
  12590. DEBUG_INFO(" compare '/' all right\n");
  12591. break;
  12592. }
  12593. i=i+1;
  12594. }
  12595. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12596. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12597. filenametemp[i+1] = 0;
  12598. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12599. pch=strchr(temp,'@');
  12600. if(pch==NULL)
  12601. {
  12602. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12603. protocol, host, &port, path);
  12604. strcpy(user,"anonymous");
  12605. strcpy(password,"");
  12606. }
  12607. else
  12608. {
  12609. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12610. protocol, user, password, host, &port, path);
  12611. }
  12612. sscanf(host,"%[^/]%s",host1, path1);
  12613. sprintf(ftppath,"%s", path1);
  12614. //DEBUG_INFO("protocol =%s\n",protocol);
  12615. //DEBUG_INFO("user =%s\n",user);
  12616. //DEBUG_INFO("password =%s\n",password);
  12617. //DEBUG_INFO("host1 =%s\n",host1);
  12618. //DEBUG_INFO("port =%d\n",port);
  12619. //DEBUG_INFO("path1 =%s\n",path1);
  12620. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12621. //ftpFile(host, user, password, port, ftppath, fname);
  12622. //download firmware pthred
  12623. if(port == 0)
  12624. {
  12625. port = 21;
  12626. }
  12627. do
  12628. {
  12629. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12630. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12631. sleep(1);
  12632. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12633. if(!isSuccess)
  12634. {
  12635. //BulldogUtil.sleepMs(interval*1000);
  12636. DEBUG_INFO("Update firmware request and download file fail.\n");
  12637. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12638. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12639. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12640. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12641. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12642. }
  12643. else
  12644. {
  12645. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12646. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12647. }
  12648. retriesInt--;
  12649. }while((!isSuccess)&&(retriesInt >= 0));
  12650. }
  12651. else
  12652. {
  12653. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12654. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12655. sleep(1);
  12656. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12657. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12658. }
  12659. // OCPPPH only, must announce CSU upgrade firmware
  12660. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12661. interLock.isUpdateFirmwareGoing = 0;
  12662. pthread_exit(NULL);
  12663. }
  12664. int handleCertificateSignedRequest(char *uuid, char *payload)
  12665. {
  12666. mtrace();
  12667. int result = PASS;
  12668. json_object *CertificateSigned;
  12669. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12670. CertificateSigned = json_tokener_parse(payload);
  12671. if(!is_error(CertificateSigned))
  12672. {
  12673. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12674. }
  12675. json_object_put(CertificateSigned);
  12676. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12677. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12678. fclose(fp);
  12679. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12680. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12681. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12682. sendCertificateSignedConfirmation(uuid);
  12683. return result;
  12684. }
  12685. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12686. {
  12687. mtrace();
  12688. int result = PASS;
  12689. json_object *DeleteCertificate;
  12690. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12691. DeleteCertificate = json_tokener_parse(payload);
  12692. if(!is_error(DeleteCertificate))
  12693. {
  12694. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12695. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12696. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12697. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12698. }
  12699. json_object_put(DeleteCertificate);
  12700. /*
  12701. * TODO: Delete certificateSigned process
  12702. */
  12703. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12704. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12705. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12706. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12707. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12708. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12709. sendDeleteCertificateConfirmation(uuid);
  12710. return result;
  12711. }
  12712. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12713. {
  12714. mtrace();
  12715. int result = PASS;
  12716. json_object *ExtendedTriggerMessage;
  12717. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12718. ExtendedTriggerMessage = json_tokener_parse(payload);
  12719. if(!is_error(ExtendedTriggerMessage))
  12720. {
  12721. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12722. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12723. {
  12724. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12725. }
  12726. else
  12727. {
  12728. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12729. }
  12730. }
  12731. json_object_put(ExtendedTriggerMessage);
  12732. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12733. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12734. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12735. {
  12736. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12737. }
  12738. else
  12739. {
  12740. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12741. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12742. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12743. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12744. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12745. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12746. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12747. {
  12748. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12749. }
  12750. else
  12751. {
  12752. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12753. }
  12754. }
  12755. sendExtendedTriggerMessageConfirmation(uuid);
  12756. //==========================
  12757. // Trigger message
  12758. //==========================
  12759. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12760. {
  12761. //sendBootNotificationRequest();
  12762. server_sign = FALSE;
  12763. }
  12764. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12765. {
  12766. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12767. }
  12768. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12769. {
  12770. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12771. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12772. {
  12773. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12774. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12775. }
  12776. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12777. }
  12778. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12779. {
  12780. refreshStartTimer(&clientTime.Heartbeat);
  12781. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12782. }
  12783. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12784. {
  12785. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12786. {
  12787. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12788. }
  12789. else
  12790. {
  12791. for(int idx=0;idx< gunTotalNumber;idx++)
  12792. {
  12793. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12794. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12795. }
  12796. }
  12797. }
  12798. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12799. {
  12800. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12801. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12802. {
  12803. 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\" &");
  12804. }
  12805. }
  12806. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12807. {
  12808. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12809. {
  12810. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12811. }
  12812. else
  12813. {
  12814. for(int idx=0;idx< gunTotalNumber;idx++)
  12815. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12816. }
  12817. }
  12818. return result;
  12819. }
  12820. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12821. {
  12822. mtrace();
  12823. int result = PASS;
  12824. json_object *GetInstalledCertificateIds;
  12825. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12826. GetInstalledCertificateIds = json_tokener_parse(payload);
  12827. if(!is_error(GetInstalledCertificateIds))
  12828. {
  12829. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12830. }
  12831. json_object_put(GetInstalledCertificateIds);
  12832. /*
  12833. * TODO: Return installed certificate process
  12834. */
  12835. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12836. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12837. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12838. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12839. sendGetInstalledCertificateIdsConfirmation(uuid);
  12840. return result;
  12841. }
  12842. int handleGetLogRequest(char *uuid, char *payload)
  12843. {
  12844. mtrace();
  12845. int result = PASS;
  12846. json_object *GetLog;
  12847. DEBUG_INFO("handleGetLogRequest...\n");
  12848. GetLog = json_tokener_parse(payload);
  12849. if(!is_error(GetLog))
  12850. {
  12851. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12852. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12853. if(json_object_object_get(GetLog, "retries") != NULL)
  12854. {
  12855. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12856. }
  12857. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12858. {
  12859. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12860. }
  12861. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12862. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12863. {
  12864. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12865. }
  12866. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12867. {
  12868. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12869. }
  12870. }
  12871. json_object_put(GetLog);
  12872. /*
  12873. * TODO: Upload log process
  12874. */
  12875. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12876. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12877. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12878. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12879. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12880. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12881. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12882. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12883. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12884. sendGetLogConfirmation(uuid);
  12885. return result;
  12886. }
  12887. int handleInstallCertificateRequest(char *uuid, char *payload)
  12888. {
  12889. mtrace();
  12890. int result = PASS;
  12891. json_object *InstallCertificate;
  12892. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12893. InstallCertificate = json_tokener_parse(payload);
  12894. if(!is_error(InstallCertificate))
  12895. {
  12896. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12897. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12898. /*
  12899. * TODO: Install certificate process
  12900. */
  12901. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12902. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12903. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12904. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12905. sendInstallCertificateConfirmation(uuid);
  12906. }
  12907. json_object_put(InstallCertificate);
  12908. return result;
  12909. }
  12910. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12911. {
  12912. mtrace();
  12913. int result = PASS;
  12914. json_object *SignedUpdateFirmware;
  12915. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12916. SignedUpdateFirmware = json_tokener_parse(payload);
  12917. if(!is_error(SignedUpdateFirmware))
  12918. {
  12919. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12920. {
  12921. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12922. }
  12923. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12924. {
  12925. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12926. }
  12927. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12928. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12929. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12930. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12931. {
  12932. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12933. }
  12934. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12935. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12936. }
  12937. json_object_put(SignedUpdateFirmware);
  12938. /*
  12939. * TODO: Upgrade firmware process
  12940. */
  12941. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12942. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12943. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12944. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12945. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12946. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12947. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12948. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12949. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12950. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12951. sendInstallCertificateConfirmation(uuid);
  12952. return result;
  12953. }
  12954. int handleUnknownRequest(char *uuid, char *payload)
  12955. {
  12956. mtrace();
  12957. int result = PASS;
  12958. DEBUG_INFO("handleUnknownRequest...\n");
  12959. sendUnknownConfirmation(uuid);
  12960. result = PASS;
  12961. return result;
  12962. }
  12963. //==========================================
  12964. // Handle server response routine
  12965. //==========================================
  12966. void handleAuthorizeResponse(char *payload, int gun_index)
  12967. {
  12968. mtrace();
  12969. char expiryDatestr[30]={0};
  12970. char parentIdTagstr[20]={0};
  12971. char statusstr[20]={0};
  12972. int expiryDateISNULL=FALSE;
  12973. int parentIdTagISNULL=FALSE;
  12974. DEBUG_INFO("handleAuthorizeResponse...\n");
  12975. json_object *Authorize;
  12976. Authorize = json_tokener_parse(payload);
  12977. if(!is_error(Authorize))
  12978. {
  12979. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12980. {
  12981. // Required data
  12982. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12983. // Optional data
  12984. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12985. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12986. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12987. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12988. }
  12989. }
  12990. json_object_put(Authorize);
  12991. if(expiryDateISNULL == FALSE)
  12992. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12993. if(parentIdTagISNULL == FALSE)
  12994. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12995. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12996. //Update idTag information to authorization cache if supproted
  12997. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12998. {
  12999. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13000. }
  13001. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13002. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13003. authorizeRetryTimes = 0;
  13004. }
  13005. void handleBootNotificationResponse(char *payload, int gun_index)
  13006. {
  13007. mtrace();
  13008. char statusStr[12]={0};
  13009. char currentTimeStr[30]={0};
  13010. int intervalInt = 0;
  13011. DEBUG_INFO("handleBootNotificationResponse...\n");
  13012. json_object *BootNotification;
  13013. BootNotification = json_tokener_parse(payload);
  13014. if(!is_error(BootNotification))
  13015. {
  13016. // Required data
  13017. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13018. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13019. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13020. }
  13021. json_object_put(BootNotification);
  13022. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13023. BootNotificationInterval = intervalInt;
  13024. //write back to ShmOCPP16DataPH->BootNotification
  13025. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13026. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13027. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13028. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13029. {
  13030. BootNotificationInterval = 0;
  13031. if((intervalInt == 0) || (intervalInt >= 10))
  13032. {
  13033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13034. HeartBeatWaitTime = intervalInt;
  13035. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13036. }
  13037. server_sign = TRUE;
  13038. server_pending =FALSE;
  13039. }
  13040. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13041. {
  13042. server_pending = TRUE;
  13043. }
  13044. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13045. srand(time(NULL));
  13046. refreshStartTimer(&clientTime.Heartbeat);
  13047. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13048. SetOcppConnStatus(TRUE);
  13049. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13050. }
  13051. void handleDataTransferResponse(char *payload, int gun_index)
  13052. {
  13053. json_object *DataTransfer = json_tokener_parse(payload);
  13054. if(!is_error(DataTransfer))
  13055. {
  13056. // Required data
  13057. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13058. // Optional data
  13059. if(json_object_object_get(DataTransfer, "data") != NULL)
  13060. {
  13061. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13062. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13063. if(!is_error(Data))
  13064. {
  13065. if(json_object_object_get(Data, "msgId") != NULL)
  13066. {
  13067. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13068. {
  13069. 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")));
  13070. }
  13071. }
  13072. }
  13073. json_object_put(Data);
  13074. }
  13075. }
  13076. json_object_put(DataTransfer);
  13077. }
  13078. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13079. {
  13080. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13081. //struct json_object *obj;
  13082. // obj = json_tokener_parse(payload);
  13083. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13084. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13085. //No fields are defined.
  13086. }
  13087. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13088. {
  13089. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13090. //struct json_object *obj;
  13091. // obj = json_tokener_parse(payload);
  13092. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13093. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13094. //No fields are defined.
  13095. }
  13096. void handleHeartbeatResponse(char *payload, int gun_index)
  13097. {
  13098. mtrace();
  13099. DEBUG_INFO("handleHeartbeatResponse...\n");
  13100. json_object *Heartbeat;
  13101. Heartbeat = json_tokener_parse(payload);
  13102. if(!is_error(Heartbeat))
  13103. {
  13104. // Required data
  13105. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13106. }
  13107. json_object_put(Heartbeat);
  13108. if(FirstHeartBeat == 0)
  13109. {
  13110. FirstHeartBeat = 1;
  13111. DEBUG_INFO("FirstHeartBeat \n");
  13112. }
  13113. HeartBeatWithNOResponse = 0;
  13114. refreshStartTimer(&clientTime.Heartbeat);
  13115. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13116. }
  13117. void handleMeterValuesResponse(char *payload, int gun_index)
  13118. {
  13119. mtrace();
  13120. DEBUG_INFO("handleMeterValuesResponse...\n");
  13121. isQueueSendable = 1;
  13122. }
  13123. void handleStartTransactionResponse(char *payload, int gun_index)
  13124. {
  13125. mtrace();
  13126. //int transactionIdInt = 0;
  13127. FILE *outfile;
  13128. char data[100]={0};
  13129. DEBUG_INFO("handleStartTransactionResponse...\n");
  13130. json_object *StartTransaction;
  13131. StartTransaction = json_tokener_parse(payload);
  13132. if(!is_error(StartTransaction))
  13133. {
  13134. // Required data
  13135. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13136. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13137. // Optional data
  13138. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13139. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13140. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13141. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13142. }
  13143. json_object_put(StartTransaction);
  13144. isQueueSendable = 1;
  13145. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13146. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13147. //-----------Start : write to the Queue TransactionId file -----------------//
  13148. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13149. {}
  13150. else
  13151. {
  13152. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13153. if(log == NULL)
  13154. {
  13155. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13156. return ;
  13157. }
  13158. else
  13159. {
  13160. fclose(log);
  13161. }
  13162. }
  13163. // open file for writing
  13164. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13165. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13166. {
  13167. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13168. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13169. fputs(data, outfile);
  13170. fclose (outfile);
  13171. }
  13172. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13173. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13174. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13175. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13176. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13177. }
  13178. void handleStatusNotificationResponse(char *payload, int gun_index)
  13179. {
  13180. mtrace();
  13181. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13182. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13183. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13184. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13185. }
  13186. void handleStopTransactionnResponse(char *payload, int gun_index)
  13187. {
  13188. mtrace();
  13189. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13190. json_object *StopTransaction;
  13191. StopTransaction = json_tokener_parse(payload);
  13192. if(!is_error(StopTransaction))
  13193. {
  13194. // Optional data
  13195. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13196. {
  13197. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13198. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13199. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13200. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13202. }
  13203. }
  13204. json_object_put(StopTransaction);
  13205. isQueueSendable = 1;
  13206. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13207. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13208. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13209. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13210. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13211. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13212. }
  13213. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13214. {
  13215. mtrace();
  13216. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13217. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13218. }
  13219. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13220. {
  13221. mtrace();
  13222. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13223. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13224. }
  13225. void handleSignCertificateResponse(char *payload, int gun_index)
  13226. {
  13227. mtrace();
  13228. DEBUG_INFO("handleSignCertificateResponse...\n");
  13229. json_object *SignCertificate;
  13230. SignCertificate = json_tokener_parse(payload);
  13231. if(!is_error(SignCertificate))
  13232. {
  13233. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13234. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13235. }
  13236. json_object_put(SignCertificate);
  13237. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13238. }
  13239. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13240. {
  13241. mtrace();
  13242. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13243. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13244. }
  13245. //==========================================
  13246. // Handle Error routine
  13247. //==========================================
  13248. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13249. {
  13250. mtrace();
  13251. #ifdef SystemLogMessage
  13252. DEBUG_INFO("errorCode: %s\n", errorCode);
  13253. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13254. DEBUG_INFO("errorDetails: %s\n", payload);
  13255. #endif
  13256. }
  13257. //===============================================
  13258. // Common routine
  13259. //===============================================
  13260. int initialConfigurationTable(void)
  13261. {
  13262. //clock_t start_t, end_t, total_t;
  13263. FILE *fp;
  13264. FILE *outfile;
  13265. char str[512]={0};
  13266. char sstr[256]={0};
  13267. int c = 0;
  13268. char *loc;
  13269. int confVersion = 13;
  13270. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13271. //start_t = clock();
  13272. //printf("Starting of the program, start_t = %ld\n", start_t);
  13273. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13274. // Check configuration file size is correct
  13275. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13276. {
  13277. struct stat st;
  13278. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13279. if(st.st_size < 3100)
  13280. {
  13281. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13282. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13283. }
  13284. }
  13285. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13286. {
  13287. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13288. if(outfile == NULL)
  13289. {
  13290. DEBUG_INFO("Error opening file\n");
  13291. return FALSE;
  13292. }
  13293. /*Core Profile*/
  13294. //AllowOfflineTxForUnknownId
  13295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13299. //AuthorizationCacheEnabled
  13300. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13304. //AuthorizeRemoteTxRequests
  13305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13309. //BlinkRepeat
  13310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13314. //ClockAlignedDataInterval
  13315. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13319. //ConnectionTimeOut
  13320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13324. //GetConfigurationMaxKeys
  13325. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13329. // HeartbeatInterval
  13330. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13334. // LightIntensity
  13335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13339. // LocalAuthorizeOffline
  13340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13344. // LocalPreAuthorize
  13345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13349. // MaxEnergyOnInvalidId
  13350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13354. // MeterValuesAlignedData
  13355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13358. 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" );
  13359. else
  13360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13362. // MeterValuesAlignedDataMaxLength
  13363. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13367. else
  13368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13370. // MeterValuesSampledData
  13371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13374. 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" );
  13375. else
  13376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13378. // MeterValuesSampledDataMaxLength
  13379. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13383. else
  13384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13386. // MeterValueSampleInterval
  13387. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13391. // MinimumStatusDuration
  13392. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13395. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13397. // NumberOfConnectors
  13398. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13401. {
  13402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13403. }
  13404. else
  13405. {
  13406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13407. }
  13408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13409. // ResetRetries
  13410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13414. // ConnectorPhaseRotation
  13415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13419. // ConnectorPhaseRotationMaxLength
  13420. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13424. // StopTransactionOnEVSideDisconnect
  13425. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13429. // StopTransactionOnInvalidId
  13430. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13434. // StopTxnAlignedData
  13435. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13439. // StopTxnAlignedDataMaxLength
  13440. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13444. // StopTxnSampledData
  13445. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13446. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13449. else
  13450. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13452. // StopTxnSampledDataMaxLength
  13453. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13456. {
  13457. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13458. }
  13459. else
  13460. {
  13461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13462. }
  13463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13464. // SupportedFeatureProfiles
  13465. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13466. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13469. // SupportedFeatureProfilesMaxLength
  13470. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13474. // TransactionMessageAttempts
  13475. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13478. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13480. // TransactionMessageRetryInterval
  13481. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13484. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13486. // UnlockConnectorOnEVSideDisconnect
  13487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13491. // WebSocketPingInterval
  13492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13493. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13496. // QueueOffLineMeterValues
  13497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13499. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13501. // AuthorizationKey
  13502. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13506. // SecurityProfile
  13507. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13509. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13511. // DefaultPrice
  13512. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13513. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13516. // CustomDisplayCostAndPrice
  13517. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13521. // CustomIdleFeeAfterStop
  13522. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13523. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13524. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13526. // SystemUptimeSec
  13527. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13531. // FreeVend
  13532. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13536. // FreeVendIdtag
  13537. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13538. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13539. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13541. // OcppServer
  13542. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13544. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13546. // MaintainServer
  13547. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13549. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13551. // StatusNotificationPeriodically
  13552. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13553. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13556. // StatusNotificationInterval
  13557. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13561. // Configuration Version
  13562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13566. //* Local Auth List Management Profile*/
  13567. #if 0
  13568. //For OCTT Test Case
  13569. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13572. #endif
  13573. #if 1
  13574. //LocalAuthListEnabled
  13575. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13579. #endif
  13580. //LocalAuthListMaxLength
  13581. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13585. //SendLocalListMaxLength
  13586. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13590. //ReserveConnectorZeroSupported
  13591. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13595. //* Smart Charging Profile */
  13596. //ChargeProfileMaxStackLevel
  13597. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13601. // ChargingScheduleAllowedChargingRateUnit
  13602. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13604. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13606. // ChargingScheduleMaxPeriods
  13607. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13611. // ConnectorSwitch3to1PhaseSupported
  13612. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13616. // MaxChargingProfilesInstalled
  13617. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13621. fclose(outfile);
  13622. }
  13623. else
  13624. {
  13625. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13626. char keystr[60]={0};
  13627. char readonlystr[10]={0};
  13628. char valuestr[256]={0};
  13629. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13630. if(fp == NULL) {
  13631. DEBUG_INFO("Error opening file");
  13632. return FALSE;
  13633. }
  13634. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13635. {
  13636. //DEBUG_INFO("Get Configuration \n");
  13637. if(strlen(str) > 0)
  13638. {
  13639. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13640. //*************************key*********************************/
  13641. if(strstr(str, "key") != NULL)
  13642. {
  13643. loc = strstr(str, "key");
  13644. c = 0;
  13645. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13646. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13647. {
  13648. sstr[c] = loc[strlen("key")+3+c];
  13649. c++;
  13650. }
  13651. sstr[c] = '\0';
  13652. strcpy(keystr,sstr);
  13653. }
  13654. //*************************readonly*********************************/
  13655. if(strstr(str, "readonly") != NULL)
  13656. {
  13657. loc = strstr(str, "readonly");
  13658. c = 0;
  13659. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13660. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13661. {
  13662. sstr[c] = loc[strlen("readonly")+2+c];
  13663. c++;
  13664. }
  13665. sstr[c] = '\0';
  13666. strcpy(readonlystr,sstr);
  13667. }
  13668. //*************************value*********************************/
  13669. if(strstr(str, "value") != NULL)
  13670. {
  13671. loc = strstr(str, "value");
  13672. c = 0;
  13673. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13674. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13675. {
  13676. sstr[c] = loc[strlen("value")+3+c];
  13677. c++;
  13678. }
  13679. sstr[c] = '\0';
  13680. strcpy(valuestr,sstr);
  13681. }
  13682. // DEBUG_INFO("keystr=%s\n",keystr);
  13683. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13684. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13685. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13686. {
  13687. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13690. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13691. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13692. }
  13693. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13694. {
  13695. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13697. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13698. }
  13699. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13700. {
  13701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13703. }
  13704. if(strcmp(keystr, "BlinkRepeat") == 0)
  13705. {
  13706. //Charger.BlinkRepeat = Integer.parseInt(value);
  13707. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13709. }
  13710. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13711. {
  13712. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13714. }
  13715. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13716. {
  13717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13719. }
  13720. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13721. {
  13722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13724. }
  13725. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13726. {
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13729. HeartBeatWaitTime = atoi(valuestr);
  13730. }
  13731. if(strcmp(keystr, "LightIntensity") == 0)
  13732. {
  13733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13735. }
  13736. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13737. {
  13738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13740. }
  13741. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13742. {
  13743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13745. }
  13746. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13747. {
  13748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13750. }
  13751. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13752. {
  13753. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13755. }
  13756. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13757. {
  13758. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13759. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13760. }
  13761. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13762. {
  13763. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13765. }
  13766. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13767. {
  13768. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13770. }
  13771. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13772. {
  13773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13775. }
  13776. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13777. {
  13778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13780. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13781. }
  13782. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13783. {
  13784. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13786. }
  13787. if(strcmp(keystr, "ResetRetries") == 0)
  13788. {
  13789. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13790. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13791. }
  13792. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13793. {
  13794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13795. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13796. }
  13797. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13798. {
  13799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13800. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13801. }
  13802. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13803. {
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13806. }
  13807. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13808. {
  13809. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13810. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13811. }
  13812. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13813. {
  13814. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13815. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13816. }
  13817. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13818. {
  13819. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13820. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13821. }
  13822. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13823. {
  13824. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13825. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13826. }
  13827. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13828. {
  13829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13830. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13831. }
  13832. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13833. {
  13834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13835. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13836. }
  13837. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13838. {
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13840. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13841. }
  13842. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13843. {
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13846. TransactionMessageAttemptsValue = atoi(valuestr);
  13847. }
  13848. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13849. {
  13850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13851. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13852. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13853. }
  13854. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13855. {
  13856. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13857. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13858. }
  13859. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13860. {
  13861. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13862. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13863. }
  13864. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13865. {
  13866. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13867. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13868. }
  13869. if(strcmp(keystr, "AuthorizationKey") == 0)
  13870. {
  13871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13872. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13873. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13874. }
  13875. if(strcmp(keystr, "SecurityProfile") == 0)
  13876. {
  13877. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13878. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13880. }
  13881. if(strcmp(keystr, "DefaultPrice") == 0)
  13882. {
  13883. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13884. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13885. }
  13886. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13887. {
  13888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13889. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13890. }
  13891. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13892. {
  13893. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13894. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13895. }
  13896. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13897. {
  13898. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13900. }
  13901. if(strcmp(keystr, "FreeVend") == 0)
  13902. {
  13903. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13904. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13905. }
  13906. if(strcmp(keystr, "FreeVendIdtag") == 0)
  13907. {
  13908. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13909. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  13910. }
  13911. if(strcmp(keystr, "OcppServer") == 0)
  13912. {
  13913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13914. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13915. }
  13916. if(strcmp(keystr, "MaintainServer") == 0)
  13917. {
  13918. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13919. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13920. }
  13921. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13922. {
  13923. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13924. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13925. }
  13926. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13927. {
  13928. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13929. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13930. }
  13931. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13932. {
  13933. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13934. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13935. }
  13936. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13937. {
  13938. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13939. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13940. }
  13941. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13942. {
  13943. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13944. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13945. }
  13946. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13947. {
  13948. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13949. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13950. }
  13951. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13952. {
  13953. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13955. }
  13956. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13957. {
  13958. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13959. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13960. }
  13961. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13962. {
  13963. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13964. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13965. }
  13966. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13967. {
  13968. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13969. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13970. }
  13971. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13972. {
  13973. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13974. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13975. }
  13976. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13977. {
  13978. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13979. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13980. }
  13981. }
  13982. }
  13983. fclose(fp);
  13984. }
  13985. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13986. {
  13987. return PASS;
  13988. }
  13989. else
  13990. {
  13991. return FAIL;
  13992. }
  13993. }
  13994. void StoreConfigurationTable(void)
  13995. {
  13996. FILE *outfile;
  13997. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13998. if(outfile == NULL)
  13999. {
  14000. DEBUG_INFO("Error opening file");
  14001. return ;
  14002. }
  14003. /*Core Profile*/
  14004. //AllowOfflineTxForUnknownId
  14005. /*
  14006. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14007. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14010. */
  14011. //DEBUG_INFO("data=%s\n",data);
  14012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14013. //AuthorizationCacheEnabled
  14014. /*
  14015. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14018. */
  14019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14020. //AuthorizeRemoteTxRequests
  14021. /*
  14022. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14025. */
  14026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14027. //BlinkRepeat
  14028. /*
  14029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14032. */
  14033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14034. //ClockAlignedDataInterval
  14035. /*
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14039. */
  14040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14041. //ConnectionTimeOut
  14042. /*
  14043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14046. */
  14047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14048. //GetConfigurationMaxKeys
  14049. /*
  14050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14053. */
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14055. // HeartbeatInterval
  14056. /*
  14057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14060. */
  14061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14062. // LightIntensity
  14063. /*
  14064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14067. */
  14068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14069. // LocalAuthorizeOffline
  14070. /*
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14074. */
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14076. // LocalPreAuthorize
  14077. /*
  14078. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14081. */
  14082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14083. // MaxEnergyOnInvalidId
  14084. /*
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14088. */
  14089. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14091. // MeterValuesAlignedData
  14092. /*
  14093. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14096. */
  14097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14098. // MeterValuesAlignedDataMaxLength
  14099. /*
  14100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14103. */
  14104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14105. // MeterValuesSampledData
  14106. /*
  14107. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14110. */
  14111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14112. // MeterValuesSampledDataMaxLength
  14113. /*
  14114. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14117. */
  14118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14119. // MeterValueSampleInterval
  14120. /*
  14121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14124. */
  14125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14126. // MinimumStatusDuration
  14127. /*
  14128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14131. */
  14132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14133. // NumberOfConnectors
  14134. /*
  14135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14138. {
  14139. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14140. }
  14141. else
  14142. {
  14143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14144. }
  14145. */
  14146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14147. // ResetRetries
  14148. /*
  14149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14152. */
  14153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14154. // ConnectorPhaseRotation
  14155. /*
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14159. */
  14160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14161. // ConnectorPhaseRotationMaxLength
  14162. /*
  14163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14166. */
  14167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14168. // StopTransactionOnEVSideDisconnect
  14169. /*
  14170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14173. */
  14174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14175. // StopTransactionOnInvalidId
  14176. /*
  14177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14180. */
  14181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14182. // StopTxnAlignedData
  14183. /*
  14184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14187. */
  14188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14189. // StopTxnAlignedDataMaxLength
  14190. /*
  14191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14194. */
  14195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14196. // StopTxnSampledData
  14197. /*
  14198. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14201. */
  14202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14203. // StopTxnSampledDataMaxLength
  14204. /*
  14205. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14208. */
  14209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14210. // SupportedFeatureProfiles
  14211. /*
  14212. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14215. */
  14216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14217. // SupportedFeatureProfilesMaxLength
  14218. /*
  14219. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14222. */
  14223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14224. // TransactionMessageAttempts
  14225. /*
  14226. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14229. */
  14230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14231. // TransactionMessageRetryInterval
  14232. /*
  14233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14236. */
  14237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14238. // UnlockConnectorOnEVSideDisconnect
  14239. /*
  14240. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14243. */
  14244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14245. // WebSocketPingInterval
  14246. /*
  14247. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14250. */
  14251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14252. // QueueOffLineMeterValues
  14253. /*
  14254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14257. */
  14258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14259. // AuthorizationKey
  14260. /*
  14261. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14264. */
  14265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14266. // SecurityProfile
  14267. /*
  14268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14271. */
  14272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14273. // DefaultPrice
  14274. /*
  14275. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14278. */
  14279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14280. // CustomDisplayCostAndPrice
  14281. /*
  14282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14285. */
  14286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14287. // CustomIdleFeeAfterStop
  14288. /*
  14289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14292. */
  14293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14294. // SystemUptimeSec
  14295. /*
  14296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14299. */
  14300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14301. // FreeVend
  14302. /*
  14303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14306. */
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14308. // FreeVendIdtag
  14309. /*
  14310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14313. */
  14314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14315. // OcppServer
  14316. /*
  14317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14320. */
  14321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14322. // MaintainServer
  14323. /*
  14324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14327. */
  14328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14329. // StatusNotificationPeriodically
  14330. /*
  14331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14334. */
  14335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14336. // StatusNotificationInterval
  14337. /*
  14338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14341. */
  14342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14343. // ConfigurationVersion
  14344. /*
  14345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14348. */
  14349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14350. //* Local Auth List Management Profile*/
  14351. //LocalAuthListEnabled
  14352. /*
  14353. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14356. */
  14357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14358. //LocalAuthListMaxLength
  14359. /*
  14360. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14363. */
  14364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14365. //SendLocalListMaxLength
  14366. /*
  14367. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14370. */
  14371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14372. //ReserveConnectorZeroSupported
  14373. /*
  14374. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14377. */
  14378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14379. //* Smart Charging Profile */
  14380. //ChargeProfileMaxStackLevel
  14381. /*
  14382. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14385. */
  14386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14387. // ChargingScheduleAllowedChargingRateUnit
  14388. /*
  14389. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14392. */
  14393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14394. // ChargingScheduleMaxPeriods
  14395. /*
  14396. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14399. */
  14400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14401. // ConnectorSwitch3to1PhaseSupported
  14402. /*
  14403. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14406. */
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14408. // MaxChargingProfilesInstalled
  14409. /*
  14410. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14413. */
  14414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14415. fclose(outfile);
  14416. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14417. }
  14418. void getKeyValue(char *keyReq)
  14419. {
  14420. int isEmpty = FALSE;
  14421. int isKnowKey = FALSE;
  14422. DEBUG_INFO("keyReq = %s\n", keyReq);
  14423. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14424. isEmpty = TRUE;
  14425. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14426. {
  14427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14429. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14430. {
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14432. }
  14433. else
  14434. {
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14436. }
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14438. isKnowKey = TRUE;
  14439. }
  14440. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14441. {
  14442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14445. {
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14447. }
  14448. else
  14449. {
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14451. }
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14453. isKnowKey = TRUE;
  14454. }
  14455. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14456. {
  14457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14459. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14460. {
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14462. }
  14463. else
  14464. {
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14466. }
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14468. isKnowKey = TRUE;
  14469. }
  14470. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14471. {
  14472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14475. {
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14477. }
  14478. else
  14479. {
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14481. }
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14483. isKnowKey = TRUE;
  14484. }
  14485. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14486. {
  14487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14490. {
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14492. }
  14493. else
  14494. {
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14496. }
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14498. isKnowKey = TRUE;
  14499. }
  14500. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14501. {
  14502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14505. {
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14507. }
  14508. else
  14509. {
  14510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14511. }
  14512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14513. isKnowKey = TRUE;
  14514. }
  14515. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14516. {
  14517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14519. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14520. {
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14522. }
  14523. else
  14524. {
  14525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14526. }
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14528. isKnowKey = TRUE;
  14529. }
  14530. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14531. {
  14532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14534. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14535. {
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14537. }
  14538. else
  14539. {
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14541. }
  14542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14543. isKnowKey = TRUE;
  14544. }
  14545. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14546. {
  14547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14549. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14550. {
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14552. }
  14553. else
  14554. {
  14555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14556. }
  14557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14558. isKnowKey = TRUE;
  14559. }
  14560. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14561. {
  14562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14564. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14565. {
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14567. }
  14568. else
  14569. {
  14570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14571. }
  14572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14573. isKnowKey = TRUE;
  14574. }
  14575. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14576. {
  14577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14579. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14580. {
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14582. }
  14583. else
  14584. {
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14586. }
  14587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14588. isKnowKey = TRUE;
  14589. }
  14590. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14591. {
  14592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14594. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14595. {
  14596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14597. }
  14598. else
  14599. {
  14600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14601. }
  14602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14603. isKnowKey = TRUE;
  14604. }
  14605. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14606. {
  14607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14609. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14610. {
  14611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14612. }
  14613. else
  14614. {
  14615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14616. }
  14617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14618. isKnowKey = TRUE;
  14619. }
  14620. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14621. {
  14622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14624. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14625. {
  14626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14627. }
  14628. else
  14629. {
  14630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14631. }
  14632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14633. isKnowKey = TRUE;
  14634. }
  14635. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14636. {
  14637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14639. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14640. {
  14641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14642. }
  14643. else
  14644. {
  14645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14646. }
  14647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14648. isKnowKey = TRUE;
  14649. }
  14650. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14651. {
  14652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14654. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14655. {
  14656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14657. }
  14658. else
  14659. {
  14660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14661. }
  14662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14663. isKnowKey = TRUE;
  14664. }
  14665. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14666. {
  14667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14669. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14670. {
  14671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14672. }
  14673. else
  14674. {
  14675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14676. }
  14677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14678. isKnowKey = TRUE;
  14679. }
  14680. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14681. {
  14682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14684. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14685. {
  14686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14687. }
  14688. else
  14689. {
  14690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14691. }
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14693. isKnowKey = TRUE;
  14694. }
  14695. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14696. {
  14697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14699. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14700. {
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14702. }
  14703. else
  14704. {
  14705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14706. }
  14707. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14709. isKnowKey = TRUE;
  14710. }
  14711. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14712. {
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14716. {
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14718. }
  14719. else
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14722. }
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14724. isKnowKey = TRUE;
  14725. }
  14726. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14727. {
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14730. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14731. {
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14733. }
  14734. else
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14737. }
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14739. isKnowKey = TRUE;
  14740. }
  14741. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14742. {
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14746. {
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14748. }
  14749. else
  14750. {
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14752. }
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14754. isKnowKey = TRUE;
  14755. }
  14756. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14757. {
  14758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14761. {
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14763. }
  14764. else
  14765. {
  14766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14767. }
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14769. isKnowKey = TRUE;
  14770. }
  14771. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14772. {
  14773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14775. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14776. {
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14778. }
  14779. else
  14780. {
  14781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14782. }
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14784. isKnowKey = TRUE;
  14785. }
  14786. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14787. {
  14788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14790. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14791. {
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14793. }
  14794. else
  14795. {
  14796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14797. }
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14799. isKnowKey = TRUE;
  14800. }
  14801. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14802. {
  14803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14805. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14806. {
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14808. }
  14809. else
  14810. {
  14811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14812. }
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14814. isKnowKey = TRUE;
  14815. }
  14816. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14817. {
  14818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14820. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14821. {
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14823. }
  14824. else
  14825. {
  14826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14827. }
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14829. isKnowKey = TRUE;
  14830. }
  14831. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14832. {
  14833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14835. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14836. {
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14838. }
  14839. else
  14840. {
  14841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14842. }
  14843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14844. isKnowKey = TRUE;
  14845. }
  14846. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14847. {
  14848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14850. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14851. {
  14852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14853. }
  14854. else
  14855. {
  14856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14857. }
  14858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14859. isKnowKey = TRUE;
  14860. }
  14861. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14862. {
  14863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14865. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14866. {
  14867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14868. }
  14869. else
  14870. {
  14871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14872. }
  14873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14874. isKnowKey = TRUE;
  14875. }
  14876. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14877. {
  14878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14880. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14881. {
  14882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14883. }
  14884. else
  14885. {
  14886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14887. }
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14889. isKnowKey = TRUE;
  14890. }
  14891. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14892. {
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14895. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14896. {
  14897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14898. }
  14899. else
  14900. {
  14901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14902. }
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14904. isKnowKey = TRUE;
  14905. }
  14906. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14907. {
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14910. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14911. {
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14913. }
  14914. else
  14915. {
  14916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14917. }
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14919. isKnowKey = TRUE;
  14920. }
  14921. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14922. {
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14925. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14926. {
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14928. }
  14929. else
  14930. {
  14931. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14932. }
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14934. isKnowKey = TRUE;
  14935. }
  14936. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14937. {
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14939. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14940. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14941. {
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14943. }
  14944. else
  14945. {
  14946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14947. }
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14949. isKnowKey = TRUE;
  14950. }
  14951. /*
  14952. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14953. {
  14954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14956. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14957. {
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14959. }
  14960. else
  14961. {
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14963. }
  14964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14965. isKnowKey = TRUE;
  14966. }*/
  14967. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14968. {
  14969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14971. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14972. {
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14974. }
  14975. else
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14978. }
  14979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14980. isKnowKey = TRUE;
  14981. }
  14982. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14983. {
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14986. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14987. {
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14989. }
  14990. else
  14991. {
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14993. }
  14994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14995. isKnowKey = TRUE;
  14996. }
  14997. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14998. {
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15001. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15002. {
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15004. }
  15005. else
  15006. {
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15008. }
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15010. isKnowKey = TRUE;
  15011. }
  15012. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15013. {
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15016. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15017. {
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15019. }
  15020. else
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15023. }
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15025. isKnowKey = TRUE;
  15026. }
  15027. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15028. {
  15029. struct sysinfo s_info;
  15030. int error = sysinfo(&s_info);
  15031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15034. {
  15035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15036. }
  15037. else
  15038. {
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15040. }
  15041. if(error != 0)
  15042. {
  15043. DEBUG_WARN("System uptime get error: %d\n", error);
  15044. }
  15045. else
  15046. {
  15047. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15048. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15049. }
  15050. isKnowKey = TRUE;
  15051. }
  15052. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15053. {
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15056. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15057. {
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15059. }
  15060. else
  15061. {
  15062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15063. }
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15065. isKnowKey = TRUE;
  15066. }
  15067. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15068. {
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15071. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15072. {
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15074. }
  15075. else
  15076. {
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15078. }
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15080. isKnowKey = TRUE;
  15081. }
  15082. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15083. {
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15086. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15087. {
  15088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15089. }
  15090. else
  15091. {
  15092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15093. }
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15095. isKnowKey = TRUE;
  15096. }
  15097. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15098. {
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15101. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15102. {
  15103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15104. }
  15105. else
  15106. {
  15107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15108. }
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15110. isKnowKey = TRUE;
  15111. }
  15112. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15113. {
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15116. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15117. {
  15118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15119. }
  15120. else
  15121. {
  15122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15123. }
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15125. isKnowKey = TRUE;
  15126. }
  15127. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15128. {
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15131. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15132. {
  15133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15134. }
  15135. else
  15136. {
  15137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15138. }
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15140. isKnowKey = TRUE;
  15141. }
  15142. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15143. {
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15146. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15147. {
  15148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15149. }
  15150. else
  15151. {
  15152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15153. }
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15155. isKnowKey = TRUE;
  15156. }
  15157. #if 1
  15158. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15159. {
  15160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15162. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15163. {
  15164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15165. }
  15166. else
  15167. {
  15168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15169. }
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15171. isKnowKey = TRUE;
  15172. }
  15173. #endif
  15174. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15175. {
  15176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15178. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15179. {
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15181. }
  15182. else
  15183. {
  15184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15185. }
  15186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15187. isKnowKey = TRUE;
  15188. }
  15189. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15190. {
  15191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15193. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15194. {
  15195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15196. }
  15197. else
  15198. {
  15199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15200. }
  15201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15202. isKnowKey = TRUE;
  15203. }
  15204. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15205. {
  15206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15208. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15209. {
  15210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15211. }
  15212. else
  15213. {
  15214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15215. }
  15216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15217. isKnowKey = TRUE;
  15218. }
  15219. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15220. {
  15221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15223. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15224. {
  15225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15226. }
  15227. else
  15228. {
  15229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15230. }
  15231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15232. isKnowKey = TRUE;
  15233. }
  15234. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15235. {
  15236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15238. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15239. {
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15241. }
  15242. else
  15243. {
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15245. }
  15246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15247. isKnowKey = TRUE;
  15248. }
  15249. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15250. {
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15253. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15254. {
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15256. }
  15257. else
  15258. {
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15260. }
  15261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15262. isKnowKey = TRUE;
  15263. }
  15264. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15265. {
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15268. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15269. {
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15271. }
  15272. else
  15273. {
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15275. }
  15276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15277. isKnowKey = TRUE;
  15278. }
  15279. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15280. {
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15283. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15284. {
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15286. }
  15287. else
  15288. {
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15290. }
  15291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15292. isKnowKey = TRUE;
  15293. }
  15294. //=========================================================
  15295. if(!isEmpty && !isKnowKey)
  15296. {
  15297. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15298. strcpy(unknownkey[UnknownKeynum], keyReq);
  15299. UnknownKeynum = UnknownKeynum + 1;
  15300. }
  15301. }
  15302. void processUnkownKey(void)
  15303. {
  15304. DEBUG_INFO("processUnkownKey...\n");
  15305. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15306. for(int index=0; index < UnknownKeynum; index++)
  15307. {
  15308. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15309. {
  15310. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15311. }
  15312. }
  15313. }
  15314. int setKeyValue(char *key, char *value)
  15315. {
  15316. int isSuccess = NotSupported;
  15317. int check_ascii=0;
  15318. char str[501]={0};
  15319. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15320. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15321. {
  15322. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15323. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15324. {
  15325. strcpy(str, (const char*)value);
  15326. for(int i = 0; str[i]; i++){
  15327. str[i] = tolower(str[i]);
  15328. }
  15329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15330. isSuccess = ConfigurationStatus_Accepted;
  15331. }
  15332. else
  15333. {
  15334. isSuccess = ConfigurationStatus_Rejected;
  15335. }
  15336. }
  15337. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15338. {
  15339. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15341. {
  15342. strcpy(str, (const char*)value);
  15343. for(int i = 0; str[i]; i++){
  15344. str[i] = tolower(str[i]);
  15345. }
  15346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15347. isSuccess = ConfigurationStatus_Accepted;
  15348. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15349. }
  15350. else
  15351. {
  15352. isSuccess = ConfigurationStatus_Rejected;
  15353. }
  15354. }
  15355. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15356. {
  15357. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15358. {
  15359. strcpy(str, (const char*)value);
  15360. for(int i = 0; str[i]; i++)
  15361. {
  15362. str[i] = tolower(str[i]);
  15363. }
  15364. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15365. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15366. isSuccess = ConfigurationStatus_Accepted;
  15367. }
  15368. else
  15369. {
  15370. isSuccess = ConfigurationStatus_Rejected;
  15371. }
  15372. }
  15373. if(strcmp(key, "BlinkRepeat") == 0)
  15374. {
  15375. //Charger.BlinkRepeat = Integer.parseInt(value);
  15376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15377. {
  15378. check_ascii = value[0];
  15379. if( (check_ascii < 48) || (check_ascii > 57) )
  15380. {
  15381. isSuccess = ConfigurationStatus_Rejected;
  15382. }
  15383. else
  15384. {
  15385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15386. isSuccess = ConfigurationStatus_Accepted;
  15387. }
  15388. }
  15389. else
  15390. {
  15391. isSuccess = ConfigurationStatus_Rejected;
  15392. }
  15393. }
  15394. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15395. {
  15396. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15397. {
  15398. check_ascii = value[0];
  15399. if( (check_ascii < 48) || (check_ascii > 57) )
  15400. {
  15401. isSuccess = ConfigurationStatus_Rejected;
  15402. }
  15403. else
  15404. {
  15405. if((atoi(value) == 0) || (atoi(value) >= 5))
  15406. {
  15407. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15408. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15409. isSuccess = ConfigurationStatus_Accepted;
  15410. }
  15411. else
  15412. isSuccess = ConfigurationStatus_Rejected;
  15413. }
  15414. }
  15415. else
  15416. {
  15417. isSuccess = ConfigurationStatus_Rejected;
  15418. }
  15419. }
  15420. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15421. {
  15422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15423. {
  15424. check_ascii = value[0];
  15425. if( (check_ascii < 48) || (check_ascii > 57) )
  15426. {
  15427. isSuccess = ConfigurationStatus_Rejected;
  15428. }
  15429. else
  15430. {
  15431. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15432. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15433. isSuccess = ConfigurationStatus_Accepted;
  15434. }
  15435. }
  15436. else
  15437. {
  15438. isSuccess = ConfigurationStatus_Rejected;
  15439. }
  15440. }
  15441. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15442. {
  15443. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15444. {
  15445. check_ascii = value[0];
  15446. if( (check_ascii < 48) || (check_ascii > 57) )
  15447. {
  15448. isSuccess = ConfigurationStatus_Rejected;
  15449. }
  15450. else
  15451. {
  15452. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15454. isSuccess = ConfigurationStatus_Accepted;
  15455. }
  15456. }
  15457. else
  15458. {
  15459. isSuccess = ConfigurationStatus_Rejected;
  15460. }
  15461. }
  15462. if(strcmp(key, "HeartbeatInterval") == 0)
  15463. {
  15464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15465. {
  15466. check_ascii = value[0];
  15467. if( (check_ascii < 48) || (check_ascii > 57) )
  15468. {
  15469. isSuccess = ConfigurationStatus_Rejected;
  15470. }
  15471. else
  15472. {
  15473. if((atoi(value) == 0) || (atoi(value) >= 10))
  15474. {
  15475. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15476. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15477. HeartBeatWaitTime = atoi(value);
  15478. isSuccess = ConfigurationStatus_Accepted;
  15479. }
  15480. else
  15481. {
  15482. isSuccess = ConfigurationStatus_Rejected;
  15483. }
  15484. }
  15485. }
  15486. else
  15487. {
  15488. isSuccess = ConfigurationStatus_Rejected;
  15489. }
  15490. }
  15491. if(strcmp(key, "LightIntensity") == 0)
  15492. {
  15493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15494. {
  15495. check_ascii = value[0];
  15496. if( (check_ascii < 48) || (check_ascii > 57) )
  15497. {
  15498. isSuccess = ConfigurationStatus_Rejected;
  15499. }
  15500. else
  15501. {
  15502. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15503. isSuccess = ConfigurationStatus_Accepted;
  15504. }
  15505. }
  15506. else
  15507. {
  15508. isSuccess = ConfigurationStatus_Rejected;
  15509. }
  15510. }
  15511. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15512. {
  15513. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15514. {
  15515. strcpy(str, (const char*)value);
  15516. for(int i = 0; str[i]; i++)
  15517. {
  15518. str[i] = tolower(str[i]);
  15519. }
  15520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15521. isSuccess = ConfigurationStatus_Accepted;
  15522. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15523. }
  15524. else
  15525. {
  15526. isSuccess = ConfigurationStatus_Rejected;
  15527. }
  15528. }
  15529. if(strcmp(key, "LocalPreAuthorize") == 0)
  15530. {
  15531. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15532. {
  15533. strcpy(str, (const char*)value);
  15534. for(int i = 0; str[i]; i++)
  15535. {
  15536. str[i] = tolower(str[i]);
  15537. }
  15538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15539. isSuccess = ConfigurationStatus_Accepted;
  15540. }
  15541. else
  15542. {
  15543. isSuccess = ConfigurationStatus_Rejected;
  15544. }
  15545. }
  15546. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15547. {
  15548. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15549. {
  15550. check_ascii = value[0];
  15551. if( (check_ascii < 48) || (check_ascii > 57) )
  15552. {
  15553. isSuccess = ConfigurationStatus_Rejected;
  15554. }
  15555. else
  15556. {
  15557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15558. isSuccess = ConfigurationStatus_Accepted;
  15559. }
  15560. }
  15561. else
  15562. {
  15563. isSuccess = ConfigurationStatus_Rejected;
  15564. }
  15565. }
  15566. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15567. {
  15568. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15569. {
  15570. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15571. isSuccess = ConfigurationStatus_Accepted;
  15572. }
  15573. else
  15574. {
  15575. isSuccess = ConfigurationStatus_Rejected;
  15576. }
  15577. }
  15578. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15579. {
  15580. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15581. {
  15582. check_ascii = value[0];
  15583. if( (check_ascii < 48) || (check_ascii > 57) )
  15584. {
  15585. isSuccess = ConfigurationStatus_Rejected;
  15586. }
  15587. else
  15588. {
  15589. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15591. isSuccess = ConfigurationStatus_Accepted;
  15592. }
  15593. }
  15594. else
  15595. {
  15596. isSuccess = ConfigurationStatus_Rejected;
  15597. }
  15598. }
  15599. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15600. {
  15601. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15602. {
  15603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15604. isSuccess = ConfigurationStatus_Accepted;
  15605. }
  15606. else
  15607. {
  15608. isSuccess = ConfigurationStatus_Rejected;
  15609. }
  15610. }
  15611. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15612. {
  15613. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15614. {
  15615. check_ascii = value[0];
  15616. if( (check_ascii < 48) || (check_ascii > 57) )
  15617. {
  15618. isSuccess = ConfigurationStatus_Rejected;
  15619. }
  15620. else
  15621. {
  15622. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15624. isSuccess = ConfigurationStatus_Accepted;
  15625. }
  15626. }
  15627. else
  15628. {
  15629. isSuccess = ConfigurationStatus_Rejected;
  15630. }
  15631. }
  15632. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15633. {
  15634. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15635. {
  15636. check_ascii = value[0];
  15637. if( (check_ascii < 48) || (check_ascii > 57) )
  15638. {
  15639. isSuccess = ConfigurationStatus_Rejected;
  15640. }
  15641. else
  15642. {
  15643. if((atoi(value) == 0) || (atoi(value) >= 3))
  15644. {
  15645. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15646. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15647. isSuccess = ConfigurationStatus_Accepted;
  15648. }
  15649. else
  15650. {
  15651. isSuccess = ConfigurationStatus_Rejected;
  15652. }
  15653. }
  15654. }
  15655. else
  15656. {
  15657. isSuccess = ConfigurationStatus_Rejected;
  15658. }
  15659. }
  15660. if(strcmp(key, "MinimumStatusDuration") == 0)
  15661. {
  15662. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15663. {
  15664. check_ascii = value[0];
  15665. if( (check_ascii < 48) || (check_ascii > 57) )
  15666. {
  15667. isSuccess = ConfigurationStatus_Rejected;
  15668. }
  15669. else
  15670. {
  15671. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15672. {
  15673. isSuccess = ConfigurationStatus_Rejected;
  15674. }
  15675. else
  15676. {
  15677. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15678. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15679. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15680. isSuccess = ConfigurationStatus_Accepted;
  15681. }
  15682. }
  15683. }
  15684. else
  15685. {
  15686. isSuccess = ConfigurationStatus_Rejected;
  15687. }
  15688. }
  15689. if(strcmp(key, "NumberOfConnectors") == 0)
  15690. {
  15691. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15692. {
  15693. check_ascii = value[0];
  15694. if( (check_ascii < 48) || (check_ascii > 57) )
  15695. {
  15696. isSuccess = ConfigurationStatus_Rejected;
  15697. }
  15698. else
  15699. {
  15700. //Charger.ResetRetries = Integer.parseInt(value);
  15701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15702. isSuccess = ConfigurationStatus_Accepted;
  15703. }
  15704. }
  15705. else
  15706. {
  15707. isSuccess = ConfigurationStatus_Rejected;
  15708. }
  15709. }
  15710. if(strcmp(key, "ResetRetries") == 0)
  15711. {
  15712. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15713. {
  15714. check_ascii = value[0];
  15715. if( (check_ascii < 48) || (check_ascii > 57) )
  15716. {
  15717. isSuccess = ConfigurationStatus_Rejected;
  15718. }
  15719. else
  15720. {
  15721. //Charger.ResetRetries = Integer.parseInt(value);
  15722. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15723. isSuccess = ConfigurationStatus_Accepted;
  15724. }
  15725. }
  15726. else
  15727. {
  15728. isSuccess = ConfigurationStatus_Rejected;
  15729. }
  15730. }
  15731. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15732. {
  15733. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15734. {
  15735. strcpy(str, (const char*)value);
  15736. for(int i = 0; str[i]; i++)
  15737. {
  15738. str[i] = tolower(str[i]);
  15739. }
  15740. if(strcmp(str, "notapplicable")== 0)
  15741. {
  15742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15743. isSuccess = ConfigurationStatus_Accepted;
  15744. }
  15745. else if(strcmp(str, "unknown")== 0)
  15746. {
  15747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15748. isSuccess = ConfigurationStatus_Accepted;
  15749. }
  15750. else if(strcmp(str, "rst")== 0)
  15751. {
  15752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15753. isSuccess = ConfigurationStatus_Accepted;
  15754. }
  15755. else if(strcmp(str, "rts")== 0)
  15756. {
  15757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15758. isSuccess = ConfigurationStatus_Accepted;
  15759. }
  15760. else if(strcmp(str, "srt")== 0)
  15761. {
  15762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15763. isSuccess = ConfigurationStatus_Accepted;
  15764. }
  15765. else if(strcmp(str, "str")== 0)
  15766. {
  15767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15768. isSuccess = ConfigurationStatus_Accepted;
  15769. }
  15770. else if(strcmp(str, "trs")== 0)
  15771. {
  15772. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15773. isSuccess = ConfigurationStatus_Accepted;
  15774. }
  15775. else if(strcmp(str, "tsr")== 0)
  15776. {
  15777. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15778. isSuccess = ConfigurationStatus_Accepted;
  15779. }
  15780. else
  15781. {
  15782. isSuccess = ConfigurationStatus_Rejected;
  15783. }
  15784. }
  15785. else
  15786. {
  15787. isSuccess = ConfigurationStatus_Rejected;
  15788. }
  15789. }
  15790. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15791. {
  15792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15793. {
  15794. check_ascii = value[0];
  15795. if( (check_ascii < 48) || (check_ascii > 57) )
  15796. {
  15797. isSuccess = ConfigurationStatus_Rejected;
  15798. }
  15799. else
  15800. {
  15801. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15802. isSuccess = ConfigurationStatus_Accepted;
  15803. }
  15804. }
  15805. else
  15806. {
  15807. isSuccess = ConfigurationStatus_Rejected;
  15808. }
  15809. }
  15810. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15811. {
  15812. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15813. {
  15814. strcpy(str, (const char*)value);
  15815. for(int i = 0; str[i]; i++)
  15816. {
  15817. str[i] = tolower(str[i]);
  15818. }
  15819. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15820. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15821. isSuccess = ConfigurationStatus_Accepted;
  15822. }
  15823. else
  15824. {
  15825. isSuccess = ConfigurationStatus_Rejected;
  15826. }
  15827. }
  15828. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15829. {
  15830. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15831. {
  15832. strcpy(str, (const char*)value);
  15833. for(int i = 0; str[i]; i++)
  15834. {
  15835. str[i] = tolower(str[i]);
  15836. }
  15837. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15839. isSuccess = ConfigurationStatus_Accepted;
  15840. }
  15841. else
  15842. {
  15843. isSuccess = ConfigurationStatus_Rejected;
  15844. }
  15845. }
  15846. if(strcmp(key, "StopTxnAlignedData") == 0)
  15847. {
  15848. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15849. {
  15850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15851. isSuccess = ConfigurationStatus_Accepted;
  15852. }
  15853. else
  15854. {
  15855. isSuccess = ConfigurationStatus_Rejected;
  15856. }
  15857. }
  15858. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15859. {
  15860. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15861. {
  15862. check_ascii = value[0];
  15863. if( (check_ascii < 48) || (check_ascii > 57) )
  15864. {
  15865. isSuccess = ConfigurationStatus_Rejected;
  15866. }
  15867. else
  15868. {
  15869. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15870. isSuccess = ConfigurationStatus_Accepted;
  15871. }
  15872. }
  15873. else
  15874. {
  15875. isSuccess = ConfigurationStatus_Rejected;
  15876. }
  15877. }
  15878. if(strcmp(key, "StopTxnSampledData") == 0)
  15879. {
  15880. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15881. {
  15882. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15883. isSuccess = ConfigurationStatus_Accepted;
  15884. }
  15885. else
  15886. {
  15887. isSuccess = ConfigurationStatus_Rejected;
  15888. }
  15889. }
  15890. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15891. {
  15892. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15893. {
  15894. check_ascii = value[0];
  15895. if( (check_ascii < 48) || (check_ascii > 57) )
  15896. {
  15897. isSuccess = ConfigurationStatus_Rejected;
  15898. }
  15899. else
  15900. {
  15901. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15902. isSuccess = ConfigurationStatus_Accepted;
  15903. }
  15904. }
  15905. else
  15906. {
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15911. {
  15912. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15913. {
  15914. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15915. isSuccess = ConfigurationStatus_Accepted;
  15916. }
  15917. else
  15918. {
  15919. isSuccess = ConfigurationStatus_Rejected;
  15920. }
  15921. }
  15922. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15923. {
  15924. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15925. {
  15926. check_ascii = value[0];
  15927. if( (check_ascii < 48) || (check_ascii > 57) )
  15928. {
  15929. isSuccess = ConfigurationStatus_Rejected;
  15930. }
  15931. else
  15932. {
  15933. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15934. isSuccess = ConfigurationStatus_Accepted;
  15935. }
  15936. }
  15937. else
  15938. {
  15939. isSuccess = ConfigurationStatus_Rejected;
  15940. }
  15941. }
  15942. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15943. {
  15944. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15945. {
  15946. check_ascii = value[0];
  15947. if( (check_ascii < 48) || (check_ascii > 57) )
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. else
  15952. {
  15953. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15955. TransactionMessageAttemptsValue = atoi(value);
  15956. isSuccess = ConfigurationStatus_Accepted;
  15957. }
  15958. }
  15959. else
  15960. {
  15961. isSuccess = ConfigurationStatus_Rejected;
  15962. }
  15963. }
  15964. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15965. {
  15966. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15967. {
  15968. check_ascii = value[0];
  15969. if( (check_ascii < 48) || (check_ascii > 57) )
  15970. {
  15971. isSuccess = ConfigurationStatus_Rejected;
  15972. }
  15973. else
  15974. {
  15975. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15976. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15977. TransactionMessageRetryIntervalValue = atoi(value);
  15978. isSuccess = ConfigurationStatus_Accepted;
  15979. }
  15980. }
  15981. else
  15982. {
  15983. isSuccess = ConfigurationStatus_Rejected;
  15984. }
  15985. }
  15986. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15987. {
  15988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15989. {
  15990. strcpy(str, (const char*)value);
  15991. for(int i = 0; str[i]; i++)
  15992. {
  15993. str[i] = tolower(str[i]);
  15994. }
  15995. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15996. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15997. isSuccess = ConfigurationStatus_Accepted;
  15998. }
  15999. else
  16000. {
  16001. isSuccess = ConfigurationStatus_Rejected;
  16002. }
  16003. }
  16004. if(strcmp(key, "WebSocketPingInterval") == 0)
  16005. {
  16006. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16007. {
  16008. check_ascii = value[0];
  16009. if( (check_ascii < 48) || (check_ascii > 57) )
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. else
  16014. {
  16015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16016. isSuccess = ConfigurationStatus_Accepted;
  16017. if((atoi(value) == 0) || (atoi(value) >= 10))
  16018. {
  16019. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16020. isSuccess = ConfigurationStatus_Accepted;
  16021. }
  16022. else
  16023. isSuccess = ConfigurationStatus_Rejected;
  16024. }
  16025. }
  16026. else
  16027. {
  16028. isSuccess = ConfigurationStatus_Rejected;
  16029. }
  16030. }
  16031. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16032. {
  16033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16034. {
  16035. strcpy(str, (const char*)value);
  16036. for(int i = 0; str[i]; i++)
  16037. {
  16038. str[i] = tolower(str[i]);
  16039. }
  16040. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16041. isSuccess = ConfigurationStatus_Accepted;
  16042. }
  16043. else
  16044. {
  16045. isSuccess = ConfigurationStatus_Rejected;
  16046. }
  16047. }
  16048. if(strcmp(key, "AuthorizationKey") == 0)
  16049. {
  16050. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16051. {
  16052. strcpy(str, (const char*)value);
  16053. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16054. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16055. isSuccess = ConfigurationStatus_Accepted;
  16056. }
  16057. else
  16058. {
  16059. isSuccess = ConfigurationStatus_Rejected;
  16060. }
  16061. }
  16062. if(strcmp(key, "SecurityProfile") == 0)
  16063. {
  16064. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16065. {
  16066. check_ascii = value[0];
  16067. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16068. {
  16069. isSuccess = ConfigurationStatus_Rejected;
  16070. }
  16071. else if(check_ascii == 0x33)
  16072. {
  16073. isSuccess = NotSupported;
  16074. }
  16075. else
  16076. {
  16077. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16078. {
  16079. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16080. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16081. isSuccess = ConfigurationStatus_Accepted;
  16082. }
  16083. else
  16084. isSuccess = ConfigurationStatus_Rejected;
  16085. }
  16086. }
  16087. else
  16088. {
  16089. isSuccess = ConfigurationStatus_Rejected;
  16090. }
  16091. }
  16092. if(strcmp(key, "DefaultPrice") == 0)
  16093. {
  16094. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16095. {
  16096. strcpy(str, (const char*)value);
  16097. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16098. isSuccess = ConfigurationStatus_Accepted;
  16099. }
  16100. else
  16101. {
  16102. isSuccess = ConfigurationStatus_Rejected;
  16103. }
  16104. }
  16105. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16106. {
  16107. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16108. {
  16109. strcpy(str, (const char*)value);
  16110. for(int i = 0; str[i]; i++)
  16111. {
  16112. str[i] = tolower(str[i]);
  16113. }
  16114. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16115. isSuccess = ConfigurationStatus_Accepted;
  16116. }
  16117. else
  16118. {
  16119. isSuccess = ConfigurationStatus_Rejected;
  16120. }
  16121. }
  16122. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16123. {
  16124. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16125. {
  16126. strcpy(str, (const char*)value);
  16127. for(int i = 0; str[i]; i++)
  16128. {
  16129. str[i] = tolower(str[i]);
  16130. }
  16131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16132. isSuccess = ConfigurationStatus_Accepted;
  16133. }
  16134. else
  16135. {
  16136. isSuccess = ConfigurationStatus_Rejected;
  16137. }
  16138. }
  16139. if(strcmp(key, "SystemUptimeSec") == 0)
  16140. {
  16141. isSuccess = NotSupported;
  16142. }
  16143. if(strcmp(key, "FreeVend") == 0)
  16144. {
  16145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16146. {
  16147. strcpy(str, (const char*)value);
  16148. for(int i = 0; str[i]; i++)
  16149. {
  16150. str[i] = tolower(str[i]);
  16151. }
  16152. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16154. isSuccess = ConfigurationStatus_Accepted;
  16155. }
  16156. else
  16157. {
  16158. isSuccess = ConfigurationStatus_Rejected;
  16159. }
  16160. }
  16161. if(strcmp(key, "FreeVendIdtag") == 0)
  16162. {
  16163. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16164. {
  16165. strcpy(str, (const char*)value);
  16166. if(strlen(str) <= 20)
  16167. {
  16168. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16169. isSuccess = ConfigurationStatus_Accepted;
  16170. }
  16171. else
  16172. {
  16173. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16174. isSuccess = ConfigurationStatus_Rejected;
  16175. }
  16176. }
  16177. else
  16178. {
  16179. isSuccess = ConfigurationStatus_Rejected;
  16180. }
  16181. }
  16182. if(strcmp(key, "OcppServer") == 0)
  16183. {
  16184. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16185. {
  16186. strcpy(str, (const char*)value);
  16187. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16188. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16189. isSuccess = ConfigurationStatus_Accepted;
  16190. }
  16191. else
  16192. {
  16193. isSuccess = ConfigurationStatus_Rejected;
  16194. }
  16195. }
  16196. if(strcmp(key, "MaintainServer") == 0)
  16197. {
  16198. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16199. {
  16200. strcpy(str, (const char*)value);
  16201. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16202. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16203. isSuccess = ConfigurationStatus_Accepted;
  16204. }
  16205. else
  16206. {
  16207. isSuccess = ConfigurationStatus_Rejected;
  16208. }
  16209. }
  16210. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16211. {
  16212. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16213. {
  16214. strcpy(str, (const char*)value);
  16215. for(int i = 0; str[i]; i++)
  16216. {
  16217. str[i] = tolower(str[i]);
  16218. }
  16219. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16220. isSuccess = ConfigurationStatus_Accepted;
  16221. }
  16222. else
  16223. {
  16224. isSuccess = ConfigurationStatus_Rejected;
  16225. }
  16226. }
  16227. if(strcmp(key, "StatusNotificationInterval") == 0)
  16228. {
  16229. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16230. {
  16231. check_ascii = value[0];
  16232. if( (check_ascii < 48) || (check_ascii > 57) )
  16233. {
  16234. isSuccess = ConfigurationStatus_Rejected;
  16235. }
  16236. else
  16237. {
  16238. if((atoi(value) == 0) || (atoi(value) >= 10))
  16239. {
  16240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16241. isSuccess = ConfigurationStatus_Accepted;
  16242. }
  16243. else
  16244. isSuccess = ConfigurationStatus_Rejected;
  16245. }
  16246. }
  16247. else
  16248. {
  16249. isSuccess = ConfigurationStatus_Rejected;
  16250. }
  16251. }
  16252. #if 0
  16253. //For OCPP Test Case
  16254. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16255. {
  16256. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16257. {
  16258. strcpy(str, (const char*)value);
  16259. for(int i = 0; str[i]; i++)
  16260. {
  16261. str[i] = tolower(str[i]);
  16262. }
  16263. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16264. isSuccess = ConfigurationStatus_Accepted;
  16265. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16266. }
  16267. else
  16268. {
  16269. isSuccess = ConfigurationStatus_Rejected;
  16270. }
  16271. }
  16272. #endif
  16273. #if 1
  16274. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16275. {
  16276. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16277. {
  16278. strcpy(str, (const char*)value);
  16279. for(int i = 0; str[i]; i++)
  16280. {
  16281. str[i] = tolower(str[i]);
  16282. }
  16283. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16284. isSuccess = ConfigurationStatus_Accepted;
  16285. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16286. }
  16287. else
  16288. {
  16289. isSuccess = ConfigurationStatus_Rejected;
  16290. }
  16291. }
  16292. #endif
  16293. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16294. {
  16295. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16296. {
  16297. check_ascii = value[0];
  16298. if( (check_ascii < 48) || (check_ascii > 57) )
  16299. {
  16300. isSuccess = ConfigurationStatus_Rejected;
  16301. }
  16302. else
  16303. {
  16304. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16305. isSuccess = ConfigurationStatus_Accepted;
  16306. }
  16307. }
  16308. else
  16309. {
  16310. isSuccess = ConfigurationStatus_Rejected;
  16311. }
  16312. }
  16313. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16314. {
  16315. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16316. {
  16317. check_ascii = value[0];
  16318. if( (check_ascii < 48) || (check_ascii > 57) )
  16319. {
  16320. isSuccess = ConfigurationStatus_Rejected;
  16321. }
  16322. else
  16323. {
  16324. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16325. isSuccess = ConfigurationStatus_Accepted;
  16326. }
  16327. }
  16328. else
  16329. {
  16330. isSuccess = ConfigurationStatus_Rejected;
  16331. }
  16332. }
  16333. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16334. {
  16335. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16336. {
  16337. strcpy(str, (const char*)value);
  16338. for(int i = 0; str[i]; i++)
  16339. {
  16340. str[i] = tolower(str[i]);
  16341. }
  16342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16343. isSuccess = ConfigurationStatus_Accepted;
  16344. }
  16345. else
  16346. {
  16347. isSuccess = ConfigurationStatus_Rejected;
  16348. }
  16349. }
  16350. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16351. {
  16352. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16353. {
  16354. check_ascii = value[0];
  16355. if( (check_ascii < 48) || (check_ascii > 57) )
  16356. {
  16357. isSuccess = ConfigurationStatus_Rejected;
  16358. }
  16359. else
  16360. {
  16361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16362. isSuccess = ConfigurationStatus_Accepted;
  16363. }
  16364. }
  16365. else
  16366. {
  16367. isSuccess = ConfigurationStatus_Rejected;
  16368. }
  16369. }
  16370. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16371. {
  16372. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16373. {
  16374. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16375. isSuccess = ConfigurationStatus_Accepted;
  16376. }
  16377. else
  16378. {
  16379. isSuccess = ConfigurationStatus_Rejected;
  16380. }
  16381. }
  16382. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16383. {
  16384. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16385. {
  16386. check_ascii = value[0];
  16387. if( (check_ascii < 48) || (check_ascii > 57) )
  16388. {
  16389. isSuccess = ConfigurationStatus_Rejected;
  16390. }
  16391. else
  16392. {
  16393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16394. isSuccess = ConfigurationStatus_Accepted;
  16395. }
  16396. }
  16397. else
  16398. {
  16399. isSuccess = ConfigurationStatus_Rejected;
  16400. }
  16401. }
  16402. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16403. {
  16404. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16405. {
  16406. strcpy(str, (const char*)value);
  16407. for(int i = 0; str[i]; i++)
  16408. {
  16409. str[i] = tolower(str[i]);
  16410. }
  16411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16412. isSuccess = ConfigurationStatus_Accepted;
  16413. }
  16414. else
  16415. {
  16416. isSuccess = ConfigurationStatus_Rejected;
  16417. }
  16418. }
  16419. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16420. {
  16421. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16422. {
  16423. check_ascii = value[0];
  16424. if( (check_ascii < 48) || (check_ascii > 57) )
  16425. {
  16426. isSuccess = ConfigurationStatus_Rejected;
  16427. }
  16428. else
  16429. {
  16430. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16431. isSuccess = ConfigurationStatus_Accepted;
  16432. }
  16433. }
  16434. else
  16435. {
  16436. isSuccess = ConfigurationStatus_Rejected;
  16437. }
  16438. }
  16439. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16440. return isSuccess;
  16441. }
  16442. int TransactionMessageAttemptsGet(void)
  16443. {
  16444. return TransactionMessageAttemptsValue;
  16445. }
  16446. int FirstHeartBeatResponse(void)
  16447. {
  16448. return FirstHeartBeat;
  16449. }
  16450. int TransactionMessageRetryIntervalGet(void)
  16451. {
  16452. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16453. }
  16454. int ReadHttpStatus(int sock)
  16455. {
  16456. //char c;
  16457. char buff[1024]="",*ptr=buff+1;
  16458. int bytes_received, status;
  16459. DEBUG_INFO("Begin Response ..\n");
  16460. while((bytes_received = recv(sock, ptr, 1, 0))){
  16461. if(bytes_received==-1){
  16462. perror("ReadHttpStatus");
  16463. exit(1);
  16464. }
  16465. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16466. ptr++;
  16467. }
  16468. *ptr=0;
  16469. ptr=buff+1;
  16470. sscanf(ptr,"%*s %d ", &status);
  16471. DEBUG_INFO("%s\n",ptr);
  16472. DEBUG_INFO("status=%d\n",status);
  16473. DEBUG_INFO("End Response ..\n");
  16474. return (bytes_received>0)?status:0;
  16475. }
  16476. //the only filed that it parsed is 'Content-Length'
  16477. int ParseHeader(int sock)
  16478. {
  16479. //char c;
  16480. char buff[1024]="",*ptr=buff+4;
  16481. int bytes_received;
  16482. DEBUG_INFO("Begin HEADER ..\n");
  16483. while((bytes_received = recv(sock, ptr, 1, 0))){
  16484. if(bytes_received==-1){
  16485. perror("Parse Header");
  16486. exit(1);
  16487. }
  16488. if(
  16489. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16490. (ptr[-1]=='\r') && (*ptr=='\n' )
  16491. ) break;
  16492. ptr++;
  16493. }
  16494. *ptr=0;
  16495. ptr=buff+4;
  16496. //printf("%s",ptr);
  16497. if(bytes_received){
  16498. ptr=strstr(ptr,"Content-Length:");
  16499. if(ptr){
  16500. sscanf(ptr,"%*s %d",&bytes_received);
  16501. }else
  16502. bytes_received=-1; //unknown size
  16503. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16504. }
  16505. DEBUG_INFO("End HEADER ..\n");
  16506. return bytes_received ;
  16507. }
  16508. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16509. {
  16510. int result = TRUE;
  16511. char rmFileCmd[100]={0};
  16512. char FilePath[100]={0};
  16513. char ftpbuf[200];
  16514. int systemresult;
  16515. sprintf(FilePath,"/mnt/%s",filename);
  16516. system("ping 8.8.8.8 &");
  16517. if((access(FilePath,F_OK))!=-1)
  16518. {
  16519. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16520. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16521. system(rmFileCmd);
  16522. }
  16523. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16524. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16525. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16526. systemresult = system(ftpbuf);
  16527. if(systemresult != 0)
  16528. {
  16529. DEBUG_INFO("http DownLoad error!\n");
  16530. result = FALSE;
  16531. }
  16532. system("pkill ping");
  16533. return result;
  16534. }
  16535. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16536. {
  16537. int result = TRUE;
  16538. char rmFileCmd[100]={0};
  16539. char FilePath[100]={0};
  16540. char ftpbuf[200];
  16541. int systemresult;
  16542. sprintf(FilePath,"/mnt/%s",filename);
  16543. system("ping 8.8.8.8 &");
  16544. if((access(FilePath,F_OK))!=-1)
  16545. {
  16546. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16547. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16548. system(rmFileCmd);
  16549. }
  16550. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16551. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16552. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16553. systemresult = system(ftpbuf);
  16554. if(systemresult != 0)
  16555. {
  16556. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16557. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16558. systemresult = system(ftpbuf);
  16559. if(systemresult != 0)
  16560. {
  16561. DEBUG_WARN("wget error!\n");
  16562. result = FALSE;
  16563. }
  16564. }
  16565. system("pkill ping");
  16566. return result;
  16567. }
  16568. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16569. {
  16570. char rmFileCmd[100]={0};
  16571. char FilePath[100]={0};
  16572. char buf[512];
  16573. int systemresult = 0;
  16574. //DEBUG_INFO("filename=%s\n",filename);
  16575. //DEBUG_INFO("url=%s\n",url);
  16576. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16577. if((access(FilePath,F_OK))!=-1)
  16578. {
  16579. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16580. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16581. system(rmFileCmd);
  16582. }
  16583. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16584. if(fp == NULL)
  16585. {
  16586. DEBUG_INFO("log is NULL\n");
  16587. return FALSE;
  16588. }
  16589. else
  16590. {
  16591. fprintf(fp, "%s\n", url);
  16592. fprintf(fp, "%s\n", filename);
  16593. fclose(fp);
  16594. }
  16595. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16596. if(phpFP == NULL)
  16597. {
  16598. DEBUG_INFO("PHP upload fail.\n");
  16599. return FALSE;
  16600. }
  16601. else
  16602. {
  16603. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16604. {
  16605. if(strstr(buf, "result") != NULL)
  16606. {
  16607. sscanf(buf, "result: %d", &systemresult);
  16608. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16609. }
  16610. }
  16611. pclose(phpFP);
  16612. }
  16613. if(systemresult != 1)
  16614. {
  16615. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  16616. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  16617. if(phpFP == NULL)
  16618. {
  16619. DEBUG_WARN("PHP PUT upload fail.\n");
  16620. return FALSE;
  16621. }
  16622. else
  16623. {
  16624. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16625. {
  16626. if(strstr(buf, "result") != NULL)
  16627. {
  16628. sscanf(buf, "result: %d", &systemresult);
  16629. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  16630. }
  16631. }
  16632. pclose(phpFP);
  16633. }
  16634. }
  16635. return TRUE;
  16636. }
  16637. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16638. {
  16639. int result = FALSE;
  16640. char ftpbuf[200];
  16641. int systemresult;
  16642. /*
  16643. // Domaind name transfer to IP address
  16644. struct hostent* server;
  16645. char *IPbuffer;
  16646. server = gethostbyname(location);
  16647. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16648. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16649. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16650. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16651. systemresult = system(ftpbuf);
  16652. if(systemresult != 0)
  16653. {
  16654. DEBUG_INFO("ftpput error!\n");
  16655. }
  16656. else
  16657. {
  16658. result = TRUE;
  16659. DEBUG_INFO("ftpput OK!\n");
  16660. }
  16661. return result;
  16662. }
  16663. int GetOcppServerURL()
  16664. {
  16665. int result = FALSE;
  16666. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16667. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16668. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16669. struct yuarel url;
  16670. char urlStr[512];
  16671. // OCPPPH only
  16672. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16673. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16674. {
  16675. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16676. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16677. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16678. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16679. if(yuarel_parse(&url, urlStr) != -1)
  16680. {
  16681. sprintf(OcppProtocol, "%s", url.scheme);
  16682. sprintf(OcppHost, "%s", url.host);
  16683. if(url.path == NULL)
  16684. OcppTempPath[0] = '\0';
  16685. else
  16686. sprintf(OcppTempPath, "%s", url.path);
  16687. if(url.port == 0)
  16688. {
  16689. if(strcmp(OcppProtocol, "wss") == 0)
  16690. OcppPort = 443;
  16691. else
  16692. OcppPort = 80;
  16693. }
  16694. else
  16695. OcppPort = url.port;
  16696. result = TRUE;
  16697. }
  16698. }
  16699. else
  16700. {
  16701. strcpy(OcppHost,"");
  16702. }
  16703. return result;
  16704. }
  16705. int GetOcppPath()
  16706. {
  16707. int result = FALSE;
  16708. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16709. {
  16710. if(OcppTempPath == NULL)
  16711. {
  16712. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16713. }
  16714. else
  16715. {
  16716. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16717. }
  16718. result = TRUE;
  16719. goto End;
  16720. }
  16721. else
  16722. {
  16723. strcpy(OcppPath,"");
  16724. }
  16725. End:
  16726. return result;
  16727. }
  16728. int GetOcppPort()
  16729. {
  16730. return OcppPort;
  16731. }
  16732. int GetOcppConnStatus(void)
  16733. {
  16734. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16735. }
  16736. void SetOcppConnStatus(uint8_t status)
  16737. {
  16738. ShmOCPP16DataPH->OcppConnStatus = status;
  16739. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16740. }
  16741. int GetHeartBeatWithNOResponse(void)
  16742. {
  16743. return HeartBeatWithNOResponse;
  16744. }
  16745. void SetHeartBeatWithNOResponse(void)
  16746. {
  16747. HeartBeatWithNOResponse = 0;
  16748. }
  16749. void GetStartTransactionIdTag(int gun_index)
  16750. {
  16751. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16752. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16753. }
  16754. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16755. {
  16756. char ch;
  16757. FILE *fptr1;
  16758. int temptransactionId;
  16759. char str[100]={0};
  16760. temptransactionId = 0;
  16761. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16762. {
  16763. DEBUG_INFO("IdTag is empty.\n");
  16764. return temptransactionId;
  16765. }
  16766. /*------ Read the file ----------------*/
  16767. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16768. if (!fptr1)
  16769. {
  16770. DEBUG_INFO("QueueTransactionId file open error.\n");
  16771. //printf(" File not found or unable to open the input file!!\n");
  16772. return temptransactionId;
  16773. }
  16774. ch=fgetc(fptr1);
  16775. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16776. rewind(fptr1);
  16777. if(ch!=EOF)
  16778. {
  16779. // printf("%c",ch);
  16780. while (fgets(str, 100, fptr1) != NULL)
  16781. {
  16782. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16783. if(str[0]=='\0')
  16784. {
  16785. break;
  16786. }
  16787. char *revbuf[8] = {0}; // Variable store string split
  16788. int num = 0;// Quantity after string split
  16789. DEBUG_INFO("Transaction queue data= %s\n", str);
  16790. splitstring(str,",",revbuf,&num); // String split
  16791. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16792. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16793. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16794. DEBUG_INFO("------------------------------\n");
  16795. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16796. {
  16797. if(isStopTransaction)
  16798. {
  16799. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16800. {
  16801. temptransactionId = atoi(revbuf[2]);
  16802. //break;
  16803. }
  16804. }
  16805. else
  16806. {
  16807. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16808. {
  16809. temptransactionId = atoi(revbuf[2]);
  16810. //break;
  16811. }
  16812. }
  16813. }
  16814. }
  16815. }
  16816. else
  16817. DEBUG_INFO("EOF\n");
  16818. fclose(fptr1);
  16819. /*------- End of reading ---------------*/
  16820. return temptransactionId;
  16821. }
  16822. void SetTransactionIdZero(int transactionId)
  16823. {
  16824. char ch;
  16825. FILE *fptr1, *fptr2;
  16826. int temptransactionId = 0;
  16827. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16828. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16829. if (!fptr1)
  16830. {
  16831. //printf(" File not found or unable to open the input file!!\n");
  16832. return ;
  16833. }
  16834. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16835. if (!fptr2)
  16836. {
  16837. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16838. fclose(fptr1);
  16839. return ;
  16840. }
  16841. ch=fgetc(fptr1);
  16842. rewind(fptr1);
  16843. if(ch!=EOF)
  16844. {
  16845. // copy all contents to the temporary file except the specific line
  16846. while (fgets(str, 100, fptr1) != NULL)
  16847. {
  16848. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16849. if(str[0]=='\0')
  16850. {
  16851. break;
  16852. }
  16853. char *revbuf[8] = {0};
  16854. int num = 0;
  16855. strcpy(strtemp, str);
  16856. splitstring(str,",",revbuf,&num);
  16857. if(revbuf[2][0] != '\0')
  16858. {
  16859. temptransactionId = atoi(revbuf[2]);
  16860. if(transactionId != temptransactionId)
  16861. {
  16862. fprintf(fptr2, "%s\n", strtemp);
  16863. }
  16864. }
  16865. }
  16866. }
  16867. fclose(fptr1);
  16868. fclose(fptr2);
  16869. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16870. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16871. /*------ Read the file ----------------*/
  16872. }
  16873. int InternetDisconnect(void)
  16874. {
  16875. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16876. }
  16877. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16878. void storeTempStopTransaction(int gun_index)
  16879. {
  16880. char guid[37]={0};
  16881. int tempIndex = 0;
  16882. char TempStopTransaction[256];
  16883. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16884. DEBUG_INFO("storeTempStopTransaction...\n");
  16885. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16886. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16887. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16888. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16889. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16890. {
  16891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16892. {
  16893. tempIndex = ((gun_index==2) ? 1: 0);
  16894. }
  16895. else
  16896. {
  16897. tempIndex = gun_index;
  16898. }
  16899. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16900. {
  16901. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16902. {
  16903. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16904. }
  16905. }// END OF CHAdeMO_QUANTITY
  16906. }
  16907. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16908. {
  16909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16910. {
  16911. tempIndex = ((gun_index==2) ? 1: 0);
  16912. }
  16913. else
  16914. {
  16915. tempIndex = gun_index;
  16916. }
  16917. for (int index = 0; index < CCS_QUANTITY; index++)
  16918. {
  16919. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16920. {
  16921. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16922. }
  16923. }// END OF CCS_QUANTITY
  16924. }
  16925. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16926. {
  16927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16928. {
  16929. tempIndex = ((gun_index==2) ? 1: 0);
  16930. }
  16931. else
  16932. {
  16933. tempIndex = gun_index;
  16934. }
  16935. for (int index = 0; index < GB_QUANTITY; index++)
  16936. {
  16937. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16938. {
  16939. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16940. }
  16941. }// END OF GB_QUANTITY
  16942. }
  16943. else if(gunType[gun_index] == GUN_TYPE_DO)
  16944. {
  16945. tempIndex = gun_index;
  16946. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16947. {
  16948. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16949. {
  16950. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16951. }
  16952. }
  16953. }
  16954. else
  16955. {
  16956. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16957. {
  16958. tempIndex = 2;
  16959. }
  16960. else
  16961. {
  16962. tempIndex = gun_index;
  16963. }
  16964. for (int index = 0; index < AC_QUANTITY; index++)
  16965. {
  16966. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16967. {
  16968. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16969. }
  16970. }// END OF AC_QUANTITY
  16971. }
  16972. //Stop Transaction Time
  16973. struct timeval tmnow;
  16974. struct tm *tm;
  16975. char buf[28];//, usec_buf[6];
  16976. gettimeofday(&tmnow, NULL);
  16977. time_t t;
  16978. t = time(NULL);
  16979. /*UTC time and date*/
  16980. tm = gmtime(&t);
  16981. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16983. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16985. random_uuid(guid);
  16986. /***********************************transactionData******************************************************/
  16987. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16989. //=================================
  16990. //1. Transaction_Begin
  16991. //=================================
  16992. //============================== Energy.Active.Import.Interval ===========================================
  16993. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16994. {
  16995. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16998. 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*/]);
  16999. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17000. 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))
  17001. {
  17002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17003. }
  17004. else
  17005. {
  17006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17007. }
  17008. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17009. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17010. }
  17011. //=================================
  17012. //2. Transaction_End
  17013. //=================================
  17014. //2.1====================================== Current.Import L1 ==============================================
  17015. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17016. {
  17017. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17018. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17019. {
  17020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17021. {
  17022. tempIndex = ((gun_index==2) ? 1: 0);
  17023. }
  17024. else
  17025. {
  17026. tempIndex = gun_index;
  17027. }
  17028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17029. {
  17030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17031. {
  17032. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17033. }
  17034. }// End of for CHAdeMO_QUANTITY
  17035. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17036. }
  17037. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17038. {
  17039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17040. {
  17041. tempIndex = ((gun_index==2) ? 1: 0);
  17042. }
  17043. else
  17044. {
  17045. tempIndex = gun_index;
  17046. }
  17047. for (int index = 0; index < CCS_QUANTITY; index++)
  17048. {
  17049. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17050. {
  17051. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17052. }
  17053. }// End of for CCS_QUANTITY
  17054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17055. }
  17056. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17057. {
  17058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17059. {
  17060. tempIndex = ((gun_index==2) ? 1: 0);
  17061. }
  17062. else
  17063. {
  17064. tempIndex = gun_index;
  17065. }
  17066. for (int index = 0; index < GB_QUANTITY; index++)
  17067. {
  17068. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17069. {
  17070. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17071. }
  17072. }// End of for GB_QUANTITY
  17073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17074. }
  17075. else if(gunType[gun_index] == GUN_TYPE_DO)
  17076. {
  17077. tempIndex = gun_index;
  17078. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17079. {
  17080. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17081. {
  17082. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17083. }
  17084. }
  17085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17086. }
  17087. else
  17088. {
  17089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17090. {
  17091. tempIndex = 2;
  17092. }
  17093. else
  17094. {
  17095. tempIndex = gun_index;
  17096. }
  17097. for (int index = 0; index < AC_QUANTITY; index++)
  17098. {
  17099. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17100. {
  17101. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17102. }
  17103. }// End of for AC_QUANTITY
  17104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17105. }
  17106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17109. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17112. }
  17113. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17114. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17115. {
  17116. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17117. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17118. {
  17119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17120. {
  17121. tempIndex = ((gun_index==2) ? 1: 0);
  17122. }
  17123. else
  17124. {
  17125. tempIndex = gun_index;
  17126. }
  17127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17128. {
  17129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17130. {
  17131. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17132. }
  17133. }// END OF CHAdeMO_QUANTITY
  17134. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17135. }
  17136. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17137. {
  17138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17139. {
  17140. tempIndex = ((gun_index==2) ? 1: 0);
  17141. }
  17142. else
  17143. {
  17144. tempIndex = gun_index;
  17145. }
  17146. for (int index = 0; index < CCS_QUANTITY; index++)
  17147. {
  17148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17149. {
  17150. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17151. }
  17152. }// END OF CCS_QUANTITY
  17153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17154. }
  17155. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17156. {
  17157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17158. {
  17159. tempIndex = ((gun_index==2) ? 1: 0);
  17160. }
  17161. else
  17162. {
  17163. tempIndex = gun_index;
  17164. }
  17165. for (int index = 0; index < GB_QUANTITY; index++)
  17166. {
  17167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17168. {
  17169. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17170. }
  17171. }// END OF GB_QUANTITY
  17172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17173. }
  17174. else if(gunType[gun_index] == GUN_TYPE_DO)
  17175. {
  17176. tempIndex = gun_index;
  17177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17178. {
  17179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17180. {
  17181. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17182. }
  17183. }
  17184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17185. }
  17186. else
  17187. {
  17188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17189. {
  17190. tempIndex = 2;
  17191. }
  17192. else
  17193. {
  17194. tempIndex = gun_index;
  17195. }
  17196. for (int index = 0; index < AC_QUANTITY; index++)
  17197. {
  17198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17199. {
  17200. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17201. }
  17202. }// END OF AC_QUANTITY
  17203. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17204. }
  17205. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17208. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17211. }
  17212. //2.3====================================== Power.Active.Import =========================================
  17213. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17214. {
  17215. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17216. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17217. {
  17218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17219. {
  17220. tempIndex = ((gun_index==2) ? 1: 0);
  17221. }
  17222. else
  17223. {
  17224. tempIndex = gun_index;
  17225. }
  17226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17227. {
  17228. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17229. {
  17230. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17231. }
  17232. } // End for CHAdeMO_QUANTITY
  17233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17234. }
  17235. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17236. {
  17237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17238. {
  17239. tempIndex = ((gun_index==2) ? 1: 0);
  17240. }
  17241. else
  17242. {
  17243. tempIndex = gun_index;
  17244. }
  17245. for (int index = 0; index < CCS_QUANTITY; index++)
  17246. {
  17247. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17248. {
  17249. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17250. }
  17251. } // END for CCS_QUANTITY
  17252. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17253. }
  17254. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17255. {
  17256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17257. {
  17258. tempIndex = ((gun_index==2) ? 1: 0);
  17259. }
  17260. else
  17261. {
  17262. tempIndex = gun_index;
  17263. }
  17264. for (int index = 0; index < GB_QUANTITY; index++)
  17265. {
  17266. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17267. {
  17268. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17269. }
  17270. }// END for GB_QUANTITY
  17271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17272. }
  17273. else if(gunType[gun_index] == GUN_TYPE_DO)
  17274. {
  17275. tempIndex = gun_index;
  17276. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17277. {
  17278. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17279. {
  17280. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17281. }
  17282. }
  17283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17284. }
  17285. else
  17286. {
  17287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17288. {
  17289. tempIndex = 2;
  17290. }
  17291. else
  17292. {
  17293. tempIndex = gun_index;
  17294. }
  17295. for (int index = 0; index < AC_QUANTITY; index++)
  17296. {
  17297. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17298. {
  17299. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17300. }
  17301. } // END for AC_QUANTITY
  17302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17303. }
  17304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17307. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17310. }
  17311. //2.4====================================== Voltage L1 ====================================================
  17312. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17313. {
  17314. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17315. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17316. {
  17317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17318. {
  17319. tempIndex = ((gun_index==2) ? 1: 0);
  17320. }
  17321. else
  17322. {
  17323. tempIndex = gun_index;
  17324. }
  17325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17326. {
  17327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17328. {
  17329. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17330. }
  17331. } // END OF FOR CHAdeMO_QUANTITY
  17332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17333. }
  17334. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17335. {
  17336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17337. {
  17338. tempIndex = ((gun_index==2) ? 1: 0);
  17339. }
  17340. else
  17341. {
  17342. tempIndex = gun_index;
  17343. }
  17344. for (int index = 0; index < CCS_QUANTITY; index++)
  17345. {
  17346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17347. {
  17348. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17349. }
  17350. } // END OF FOR CCS_QUANTITY
  17351. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17352. }
  17353. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17354. {
  17355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17356. {
  17357. tempIndex = ((gun_index==2) ? 1: 0);
  17358. }
  17359. else
  17360. {
  17361. tempIndex = gun_index;
  17362. }
  17363. for (int index = 0; index < GB_QUANTITY; index++)
  17364. {
  17365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17366. {
  17367. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17368. }
  17369. } // END OF FOR GB_QUANTITY
  17370. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17371. }
  17372. else if(gunType[gun_index] == GUN_TYPE_DO)
  17373. {
  17374. tempIndex = gun_index;
  17375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17376. {
  17377. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17378. {
  17379. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17380. }
  17381. }
  17382. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17383. }
  17384. else
  17385. {
  17386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17387. {
  17388. tempIndex = 2;
  17389. }
  17390. else
  17391. {
  17392. tempIndex = gun_index;
  17393. }
  17394. for (int index = 0; index < AC_QUANTITY; index++)
  17395. {
  17396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17397. {
  17398. 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
  17399. }
  17400. } // END OF FOR AC_QUANTITY
  17401. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17402. }
  17403. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17404. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17405. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17406. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17409. }
  17410. //2.5============================================== End SoC =========================================================
  17411. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17412. {
  17413. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17414. 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))
  17415. {
  17416. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17417. {
  17418. tempIndex = ((gun_index==2) ? 1: 0);
  17419. }
  17420. else
  17421. {
  17422. tempIndex = gun_index;
  17423. }
  17424. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17425. {
  17426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17427. {
  17428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17429. {
  17430. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17431. }
  17432. }
  17433. }
  17434. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17435. {
  17436. for (int index = 0; index < CCS_QUANTITY; index++)
  17437. {
  17438. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17439. {
  17440. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17441. }
  17442. }
  17443. }
  17444. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17445. {
  17446. for (int index = 0; index < GB_QUANTITY; index++)
  17447. {
  17448. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17449. {
  17450. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17451. }
  17452. }
  17453. }
  17454. else if(gunType[gun_index] == GUN_TYPE_DO)
  17455. {
  17456. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17457. {
  17458. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17459. {
  17460. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17461. }
  17462. }
  17463. }
  17464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17466. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17468. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17470. } // END FOR DC CASE
  17471. }
  17472. //2.6====================================== Current.Import L2 ==============================================
  17473. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17474. {
  17475. // AC 3 phase L2 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[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17491. }
  17492. }// End of for AC_QUANTITY
  17493. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17494. }
  17495. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17499. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17500. }
  17501. //2.7====================================== Current.Import L3 ==============================================
  17502. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17503. {
  17504. // AC 3 phase L3 current
  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[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17520. }
  17521. }// End of for AC_QUANTITY
  17522. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17523. }
  17524. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17525. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17527. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17528. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17529. }
  17530. //2.9====================================== Voltage L2 ====================================================
  17531. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17532. {
  17533. // AC 3 phase L2 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[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//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[8].Phase,PhaseStr[L2_N]);
  17552. }
  17553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17555. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17558. }
  17559. //2.10====================================== Voltage L3 ====================================================
  17560. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17561. {
  17562. // AC 3 phase L3 volatge
  17563. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17564. {
  17565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17566. {
  17567. tempIndex = 2;
  17568. }
  17569. else
  17570. {
  17571. tempIndex = gun_index;
  17572. }
  17573. for (int index = 0; index < AC_QUANTITY; index++)
  17574. {
  17575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17576. {
  17577. 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
  17578. }
  17579. } // END OF FOR AC_QUANTITY
  17580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17581. }
  17582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17587. }
  17588. //====================== Start SoC ================================
  17589. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17590. {
  17591. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17592. 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))
  17593. {
  17594. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17595. {
  17596. tempIndex = ((gun_index==2) ? 1: 0);
  17597. }
  17598. else
  17599. {
  17600. tempIndex = gun_index;
  17601. }
  17602. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17603. {
  17604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17605. {
  17606. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17607. {
  17608. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17609. }
  17610. }
  17611. }
  17612. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17613. {
  17614. for (int index = 0; index < CCS_QUANTITY; index++)
  17615. {
  17616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17617. {
  17618. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17619. }
  17620. }
  17621. }
  17622. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17623. {
  17624. for (int index = 0; index < GB_QUANTITY; index++)
  17625. {
  17626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17627. {
  17628. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17629. }
  17630. }
  17631. }
  17632. else if(gunType[gun_index] == GUN_TYPE_DO)
  17633. {
  17634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17635. {
  17636. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17637. {
  17638. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17639. }
  17640. }
  17641. }
  17642. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17643. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17644. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17645. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17648. } // END FOR DC CASE
  17649. }
  17650. //======================================== Message create ==============================================
  17651. json_object *StopTransaction = json_object_new_object();
  17652. json_object *transactionDatas = json_object_new_array();
  17653. json_object *sampledValues = json_object_new_array();
  17654. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17655. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17656. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17657. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17658. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17659. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17660. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17661. {
  17662. json_object *transactionData = json_object_new_object();
  17663. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17664. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17665. {
  17666. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17667. {
  17668. json_object *sampledValue = json_object_new_object();
  17669. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17670. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17671. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17672. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17673. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17674. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17675. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17676. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17677. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17678. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17679. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17680. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17681. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17682. json_object_array_add(sampledValues, sampledValue);
  17683. }
  17684. }
  17685. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17686. json_object_array_add(transactionDatas, transactionData);
  17687. }
  17688. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17689. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17690. ,MESSAGE_TYPE_CALL
  17691. ,guid
  17692. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17693. json_object_put(StopTransaction);
  17694. // Check File "TempStopTransaction" Exist
  17695. if((access(TempStopTransaction,F_OK))!=-1)
  17696. {
  17697. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17698. fclose(fopen(TempStopTransaction, "w"));
  17699. }
  17700. else
  17701. {
  17702. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17703. FILE *log = fopen(TempStopTransaction, "w+");
  17704. if(log == NULL)
  17705. {
  17706. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17707. return ;
  17708. }
  17709. else
  17710. {
  17711. fclose(log);
  17712. }
  17713. }
  17714. //Add TempStopTransaction | Update TempStopTransaction
  17715. // open file for writing
  17716. FILE *outfile;
  17717. outfile = fopen (TempStopTransaction, "a");
  17718. //DEBUG_INFO("data = %s\n", queuedata);
  17719. fputs(queuedata, outfile);
  17720. fputs("\n", outfile);
  17721. fclose (outfile);
  17722. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17723. }
  17724. void checkTempStopTransaction(int gun_index)
  17725. {
  17726. FILE *fptr1;
  17727. char ch;
  17728. char str[QUEUE_MESSAGE_LENGTH]={0};
  17729. char guid[37]={0};
  17730. char tempdata[65]={0};
  17731. char connectorStr[2]={0};
  17732. char TempStopTransaction[256];
  17733. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17734. fptr1 = fopen(TempStopTransaction, "r");
  17735. //TempStopTransaction格式: 槍號,StopTransaction封包
  17736. if (!fptr1)
  17737. {
  17738. //printf(" File not found or unable to open the input file!!\n");
  17739. return ;
  17740. }
  17741. ch=fgetc(fptr1);
  17742. //printf(" Now the content of the file %s is : \n",fname);
  17743. rewind(fptr1);
  17744. if(ch!=EOF)
  17745. {
  17746. // copy all contents to the temporary file except the specific line
  17747. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17748. {
  17749. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17750. if(str[0]=='\0')
  17751. {
  17752. break;
  17753. }
  17754. //TempStopTransaction格式: 槍號,StopTransaction封包
  17755. strncpy(connectorStr, str, 1);
  17756. if(atoi(connectorStr) != (gun_index+1))
  17757. {
  17758. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17759. fclose(fptr1);
  17760. return ;
  17761. }
  17762. //random_uuid(guid);
  17763. strncpy(guid, str+6, 36); //copy guid
  17764. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17765. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17766. {
  17767. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17768. }
  17769. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17770. OCPP_insert_transaction_msg(NO, str);
  17771. memset(str,0,ARRAY_SIZE(str));
  17772. }
  17773. }
  17774. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17775. fclose(fptr1);
  17776. remove(TempStopTransaction); // remove the original file
  17777. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17778. }
  17779. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17780. {
  17781. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17782. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17783. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17784. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17785. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17786. }
  17787. int GetWebSocketPingInterval(void)
  17788. {
  17789. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17790. }
  17791. int GetServerSign(void)
  17792. {
  17793. return server_sign;
  17794. }
  17795. uint8_t GetOcppSecurityProfile()
  17796. {
  17797. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17798. }
  17799. void GetOcppChargerBoxId(uint8_t *data)
  17800. {
  17801. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17802. }
  17803. void GetOcppSecurityPassword(uint8_t *data)
  17804. {
  17805. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17806. }
  17807. void SetOcppVersion(uint8_t *version)
  17808. {
  17809. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17810. DEBUG_INFO("ocpp version: %s\n", version);
  17811. if(strstr((char*)version, "ocpp1.6") != NULL)
  17812. {
  17813. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17814. }
  17815. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17816. {
  17817. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17818. system("pkill OcppBackend");
  17819. }
  17820. }
  17821. void SetServerSign(int value)
  17822. {
  17823. server_sign = value;
  17824. }
  17825. int GetBootNotificationInterval(void)
  17826. {
  17827. return BootNotificationInterval;
  17828. }
  17829. int GetInternetConn(void)
  17830. {
  17831. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17832. }
  17833. int GetBackendConnectionTimeout(void)
  17834. {
  17835. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17836. }
  17837. int isConnectorInitMode(int gun_index)
  17838. {
  17839. int tempIndex = 0;
  17840. int result = TRUE;
  17841. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17842. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17843. {
  17844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17845. {
  17846. tempIndex = ((gun_index==2) ? 1: 0);
  17847. }
  17848. else
  17849. {
  17850. tempIndex = gun_index;
  17851. }
  17852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17853. {
  17854. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17855. {
  17856. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17857. } //end of the same index
  17858. }//end of for CHAdeMO_QUANTITY
  17859. }
  17860. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17861. {
  17862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17863. {
  17864. tempIndex = ((gun_index==2) ? 1: 0);
  17865. }
  17866. else
  17867. {
  17868. tempIndex = gun_index;
  17869. }
  17870. for (int index = 0; index < CCS_QUANTITY; index++)
  17871. {
  17872. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17873. {
  17874. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17875. } //end of the same index
  17876. } // end of for CCS_QUANTITY
  17877. }
  17878. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17879. {
  17880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17881. {
  17882. tempIndex = ((gun_index==2) ? 1: 0);
  17883. }
  17884. else
  17885. {
  17886. tempIndex = gun_index;
  17887. }
  17888. for (int index = 0; index < GB_QUANTITY; index++)
  17889. {
  17890. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17891. {
  17892. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17893. } //end of the same index
  17894. } // end of for GB_QUANTITY
  17895. }
  17896. else if(gunType[gun_index] == GUN_TYPE_DO)
  17897. {
  17898. tempIndex = gun_index;
  17899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17900. {
  17901. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17902. {
  17903. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17904. } //end of the same index
  17905. }
  17906. }
  17907. else
  17908. {
  17909. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17910. {
  17911. tempIndex = 2;
  17912. }
  17913. else
  17914. {
  17915. tempIndex = gun_index;
  17916. }
  17917. for (int index = 0; index < AC_QUANTITY; index++)
  17918. {
  17919. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17920. {
  17921. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17922. }//end of the same index
  17923. }//end of for AC_QUANTITY
  17924. }
  17925. return result;
  17926. }
  17927. void refreshProcDogTimer()
  17928. {
  17929. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17930. }
  17931. void InitialSystemValue(void)
  17932. {
  17933. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17934. locallistVersion=0;
  17935. BootNotificationInterval = 0;
  17936. authorizeRetryTimes = 0;
  17937. GunStatusInterval = 10;
  17938. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17939. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17940. //Hear Beat
  17941. HeartBeatWithNOResponse = 0;
  17942. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17943. FirstHeartBeat = 0;
  17944. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17945. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17946. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17947. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17948. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17949. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17950. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17951. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17952. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17953. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17954. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17955. //Status && ConnectorPlugIn Setting
  17956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17957. {
  17958. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17959. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17960. }
  17961. for (int index = 0; index < CCS_QUANTITY; index++)
  17962. {
  17963. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17964. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17965. }
  17966. for (int index = 0; index < GB_QUANTITY; index++)
  17967. {
  17968. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17969. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17970. }
  17971. for (int index = 0; index < AC_QUANTITY; index++)
  17972. {
  17973. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17974. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17975. }
  17976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17977. {
  17978. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17979. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17980. }
  17981. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17982. {
  17983. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17984. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17985. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17986. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17987. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17988. }
  17989. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17990. refreshStartTimer(&clientTime.Heartbeat);
  17991. sleep(1);
  17992. }
  17993. void LWS_Send(char *str)
  17994. {
  17995. //=====================================================
  17996. // Check InternetConn 0: disconnected, 1: connected
  17997. //====================================================
  17998. if(GetOcppConnStatus() == 0)
  17999. {
  18000. DEBUG_INFO("offline now !!!\n");
  18001. return;
  18002. }
  18003. // Only disable isWebsocketSendable operation initiated by charger
  18004. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18005. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18006. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18007. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18008. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18009. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18010. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18011. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18012. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18013. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18014. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18015. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18016. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18017. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18018. {
  18019. isWebsocketSendable = 0;
  18020. }
  18021. pthread_mutex_lock(&lock_send);
  18022. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18023. sprintf((char *)SendBuffer, "%s", str);
  18024. SendBufLen = strlen(str);
  18025. pthread_mutex_unlock(&lock_send);
  18026. lws_callback_on_writable(wsi_client);
  18027. //lws_service(context, 0);
  18028. //sleep(1);
  18029. }
  18030. void LWS_SendNow(char *str)
  18031. {
  18032. //=====================================================
  18033. // Check InternetConn 0: disconnected, 1: connected
  18034. //====================================================
  18035. if(GetOcppConnStatus() == 0)
  18036. {
  18037. DEBUG_INFO("offline now !!!\n");
  18038. return;
  18039. }
  18040. // Only disable isWebsocketSendable operation initiated by charger
  18041. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18042. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18043. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18044. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18045. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18046. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18047. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18048. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18049. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18050. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18051. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18052. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18053. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18054. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18055. {
  18056. isWebsocketSendable = 0;
  18057. }
  18058. pthread_mutex_lock(&lock_send);
  18059. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18060. sprintf((char *)SendBuffer, "%s", str);
  18061. SendBufLen = strlen(str);
  18062. pthread_mutex_unlock(&lock_send);
  18063. lws_callback_on_writable(wsi_client);
  18064. lws_service(context, 0);
  18065. //sleep(1);
  18066. }