MessageHandler.c 910 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562
  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 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. //==========================================
  735. // Check time passed since today
  736. //==========================================
  737. long long DiffTimebWithNow(struct timeb ST)
  738. {
  739. //return milli-second
  740. struct timeb ET;
  741. long long StartTime,StopTime;
  742. ftime(&ET);
  743. StartTime=(long long)ST.time;
  744. StopTime=(long long)ET.time;
  745. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  746. }
  747. int getTimePassSinceToday(uint8_t gun_index)
  748. {
  749. int result = -1;
  750. static time_t lastTime[4];
  751. time_t t;
  752. struct tm *tmStartToday;
  753. struct timeb tbStartToday;
  754. t=time(NULL);
  755. if(difftime(t, lastTime[gun_index])>0)
  756. {
  757. tmStartToday=localtime(&t);
  758. tmStartToday->tm_hour = 0;
  759. tmStartToday->tm_min = 0;
  760. tmStartToday->tm_sec = 0;
  761. tbStartToday.time = mktime(tmStartToday);
  762. tbStartToday.millitm = 0;
  763. result = DiffTimebWithNow(tbStartToday)/1000;
  764. lastTime[gun_index] = t;
  765. }
  766. return result;
  767. }
  768. void getNowDatetime(uint8_t *data)
  769. {
  770. time_t t = time(NULL);
  771. struct tm tm = *localtime(&t);
  772. 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);
  773. }
  774. int syncDateTimeRTC(uint8_t *data)
  775. {
  776. struct ParsingResult
  777. {
  778. int result;
  779. int scanedElement;
  780. int year;
  781. int month;
  782. int mday;
  783. int hour;
  784. int min;
  785. int sec;
  786. int tz_hour;
  787. int tz_min;
  788. float minSec;
  789. }result;
  790. struct tm tmOrg;
  791. struct tm *tmTarget;
  792. struct timeb tbTarget;
  793. char buf[128];
  794. memset(&result, 0x00, sizeof(struct ParsingResult));
  795. result.result = PASS;
  796. if(strstr((char*)data, ".") != NULL)
  797. {
  798. // Original data with mini second
  799. if(strstr((char*)data, "Z") != NULL)
  800. {
  801. // Original data with Z
  802. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  803. &result.year,
  804. &result.month,
  805. &result.mday,
  806. &result.hour,
  807. &result.min,
  808. &result.sec,
  809. &result.minSec);
  810. }
  811. else
  812. {
  813. // Original data without Z
  814. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  815. &result.year,
  816. &result.month,
  817. &result.mday,
  818. &result.hour,
  819. &result.min,
  820. &result.sec,
  821. &result.minSec,
  822. &result.tz_hour,
  823. &result.tz_min);
  824. }
  825. }
  826. else
  827. {
  828. // Original data without mini second
  829. if(strstr((char*)data, "Z") != NULL)
  830. {
  831. // Original data with Z
  832. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  833. &result.year,
  834. &result.month,
  835. &result.mday,
  836. &result.hour,
  837. &result.min,
  838. &result.sec);
  839. }
  840. else
  841. {
  842. // Original data without Z
  843. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  844. &result.year,
  845. &result.month,
  846. &result.mday,
  847. &result.hour,
  848. &result.min,
  849. &result.sec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. tmOrg.tm_year = result.year - 1900;
  855. tmOrg.tm_mon = result.month - 1;
  856. tmOrg.tm_mday = result.mday;
  857. tmOrg.tm_hour = result.hour;
  858. tmOrg.tm_min = result.min;
  859. tmOrg.tm_sec = result.sec;
  860. tmOrg.tm_gmtoff = 0;
  861. tbTarget.time = mktime(&tmOrg);
  862. tbTarget.timezone = 0;
  863. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  864. tmTarget = gmtime(&tbTarget.time);
  865. 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);
  866. //DEBUG_INFO(" org date time: %s\n", data);
  867. //DEBUG_INFO("parse date time: %s\n", buf);
  868. system(buf);
  869. system("/sbin/hwclock -w --systohc");
  870. if(result.scanedElement < 6)
  871. result.result = FAIL;
  872. return result.result;
  873. }
  874. //==========================================
  875. // GetCompositeSchedule logic related function
  876. //==========================================
  877. int DiffTimebSec(struct timeb ST, struct timeb ET)
  878. {
  879. //return milli-second
  880. unsigned int StartTime,StopTime;
  881. StartTime=(unsigned int)ST.time;
  882. StopTime=(unsigned int)ET.time;
  883. return (StopTime-StartTime);
  884. }
  885. int DiffTimebWithNowSec(struct timeb ST)
  886. {
  887. //return milli-second
  888. struct timeb ET;
  889. unsigned int StartTime,StopTime;
  890. ftime(&ET);
  891. StartTime=(unsigned int)ST.time;
  892. StopTime=(unsigned int)ET.time;
  893. return (StopTime-StartTime);
  894. }
  895. int getStartStop(uint8_t *start, uint8_t *stop)
  896. {
  897. int result = -1;
  898. struct tm tmStart;
  899. struct timeb tbStart;
  900. struct tm tmStop;
  901. struct timeb tbStop;
  902. 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) &&
  903. (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))
  904. {
  905. //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);
  906. //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);
  907. tmStart.tm_year -= 1900;
  908. tmStart.tm_mon -= 1;
  909. tbStart.time = mktime(&tmStart);
  910. tbStart.millitm = 0;
  911. tmStop.tm_year -= 1900;
  912. tmStop.tm_mon -= 1;
  913. tbStop.time = mktime(&tmStop);
  914. tbStop.millitm = 0;
  915. result = DiffTimebSec(tbStart, tbStop);
  916. //DEBUG_INFO("getStartStop(): %d\n", result);
  917. }
  918. else
  919. {
  920. DEBUG_WARN("Start or stop date parsing error.\r\n");
  921. }
  922. return result;
  923. }
  924. int isOvertNow(uint8_t *start)
  925. {
  926. int result = NO;
  927. struct ParsingResult
  928. {
  929. int result;
  930. int scanedElement;
  931. int year;
  932. int month;
  933. int mday;
  934. int hour;
  935. int min;
  936. int sec;
  937. int tz_hour;
  938. int tz_min;
  939. float minSec;
  940. }parsingResult;
  941. struct tm tmStart;
  942. struct timeb tbStart;
  943. if(strstr((char*)start, ".") != NULL)
  944. {
  945. // Original data with mini second
  946. if(strstr((char*)start, "Z") != NULL)
  947. {
  948. // Original data with Z
  949. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  950. &parsingResult.year,
  951. &parsingResult.month,
  952. &parsingResult.mday,
  953. &parsingResult.hour,
  954. &parsingResult.min,
  955. &parsingResult.sec,
  956. &parsingResult.minSec);
  957. }
  958. else
  959. {
  960. // Original data without Z
  961. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  962. &parsingResult.year,
  963. &parsingResult.month,
  964. &parsingResult.mday,
  965. &parsingResult.hour,
  966. &parsingResult.min,
  967. &parsingResult.sec,
  968. &parsingResult.minSec,
  969. &parsingResult.tz_hour,
  970. &parsingResult.tz_min);
  971. }
  972. }
  973. else
  974. {
  975. // Original data without mini second
  976. if(strstr((char*)start, "Z") != NULL)
  977. {
  978. // Original data with Z
  979. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  980. &parsingResult.year,
  981. &parsingResult.month,
  982. &parsingResult.mday,
  983. &parsingResult.hour,
  984. &parsingResult.min,
  985. &parsingResult.sec);
  986. }
  987. else
  988. {
  989. // Original data without Z
  990. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  991. &parsingResult.year,
  992. &parsingResult.month,
  993. &parsingResult.mday,
  994. &parsingResult.hour,
  995. &parsingResult.min,
  996. &parsingResult.sec,
  997. &parsingResult.tz_hour,
  998. &parsingResult.tz_min);
  999. }
  1000. }
  1001. if(parsingResult.scanedElement >= 6)
  1002. {
  1003. tmStart.tm_year = parsingResult.year - 1900;
  1004. tmStart.tm_mon = parsingResult.month - 1;
  1005. tmStart.tm_mday = parsingResult.mday;
  1006. tmStart.tm_hour = parsingResult.hour;
  1007. tmStart.tm_min = parsingResult.min;
  1008. tmStart.tm_sec = parsingResult.sec;
  1009. tmStart.tm_gmtoff = 0;
  1010. tbStart.time = mktime(&tmStart);
  1011. tbStart.timezone = 0;
  1012. tbStart.millitm = 0;
  1013. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1014. if(DiffTimebWithNowSec(tbStart) <= 0)
  1015. result = NO;
  1016. else
  1017. result = YES;
  1018. }
  1019. else
  1020. {
  1021. DEBUG_WARN("Start date parsing error.\n");
  1022. }
  1023. return result;
  1024. }
  1025. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1026. {
  1027. int result = -1;
  1028. struct tm tmStart;
  1029. struct timeb tbStart;
  1030. struct tm tmStop;
  1031. struct timeb tbStop;
  1032. 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) &&
  1033. (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))
  1034. {
  1035. tmStart.tm_year -= 1900;
  1036. tmStart.tm_mon -= 1;
  1037. tbStart.time = mktime(&tmStart);
  1038. tbStart.millitm = 0;
  1039. tmStop.tm_year -= 1900;
  1040. tmStop.tm_mon -= 1;
  1041. tbStop.time = mktime(&tmStop);
  1042. tbStop.millitm = 0;
  1043. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1044. }
  1045. return result;
  1046. }
  1047. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1048. {
  1049. FILE *fp;
  1050. char profileFileName[128];
  1051. char *line = NULL;
  1052. size_t len = 0;
  1053. time_t CurrentTime;
  1054. struct tm *tmComposite;
  1055. struct StructChargingProfile maxProfile;
  1056. struct StructChargingProfile compositeProfile;
  1057. uint8_t limitMax=0;
  1058. int compositePeriodIdx = 0;
  1059. CurrentTime = time(NULL);
  1060. tmComposite=localtime(&CurrentTime);
  1061. 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);
  1062. if(isUnitA)
  1063. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1064. else
  1065. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1066. compositeProfile.ChargingSchedule.Duration = durationReq;
  1067. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1068. {
  1069. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1070. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1071. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1072. }
  1073. compositeProfile.ChargingProfileId = 0;
  1074. compositeProfile.StackLevel = 99 ;
  1075. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1076. maxProfile.ChargingProfileId = -1;
  1077. maxProfile.ChargingSchedule.Duration = -1;
  1078. system("rm -f /tmp/*.json");
  1079. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1080. // Search max profile
  1081. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1082. if((access(profileFileName, F_OK))!=-1)
  1083. {
  1084. fp = fopen(profileFileName, "r");
  1085. while(getline(&line, &len, fp) != -1)
  1086. {
  1087. json_object *obj = NULL;
  1088. obj = json_tokener_parse(line);
  1089. if(is_error(obj))
  1090. {
  1091. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1092. }
  1093. else
  1094. {
  1095. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1096. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1097. )
  1098. {
  1099. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1100. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1101. )
  1102. {
  1103. struct tm tmFrom, tmTo;
  1104. struct timeb tbFrom, tbTo;
  1105. 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) &&
  1106. (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))
  1107. {
  1108. tmFrom.tm_year -= 1900;
  1109. tmFrom.tm_mon -= 1;
  1110. tbFrom.time = mktime(&tmFrom);
  1111. tmTo.tm_year -= 1900;
  1112. tmTo.tm_mon -= 1;
  1113. tbTo.time = mktime(&tmTo);
  1114. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1115. {
  1116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1117. {
  1118. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1119. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1120. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1121. }
  1122. maxProfile.ChargingProfileId = -1;
  1123. maxProfile.StackLevel = -1;
  1124. if(maxProfile.ChargingProfileId == -1)
  1125. DEBUG_INFO("MaxProfile found.\n");
  1126. else
  1127. DEBUG_INFO("MaxProfile updated.\n");
  1128. // Required item
  1129. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1130. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1131. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1132. if(isUnitA)
  1133. {
  1134. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1135. 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++)
  1136. {
  1137. 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"));
  1138. 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?
  1139. 3:
  1140. 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")));
  1141. 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")));
  1142. }
  1143. }
  1144. else
  1145. {
  1146. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1147. 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++)
  1148. {
  1149. 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"));
  1150. 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?
  1151. 3:
  1152. 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")));
  1153. 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));
  1154. }
  1155. }
  1156. // Optional item
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1158. {
  1159. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1160. }
  1161. else
  1162. {
  1163. sprintf((char*)maxProfile.ValidFrom, " ");
  1164. }
  1165. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1166. {
  1167. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1168. }
  1169. else
  1170. {
  1171. sprintf((char*)maxProfile.ValidTo, " ");
  1172. }
  1173. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1174. {
  1175. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1180. }
  1181. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1182. {
  1183. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.TransactionId = -1;
  1188. }
  1189. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1190. {
  1191. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1192. }
  1193. else
  1194. {
  1195. maxProfile.ChargingSchedule.Duration = 86400;
  1196. }
  1197. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1198. {
  1199. 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")));
  1200. }
  1201. else
  1202. {
  1203. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1204. }
  1205. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1206. {
  1207. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1208. }
  1209. else
  1210. {
  1211. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1212. }
  1213. }
  1214. }
  1215. }
  1216. else
  1217. {
  1218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1219. {
  1220. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1221. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1222. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1223. }
  1224. maxProfile.ChargingProfileId = -1;
  1225. maxProfile.StackLevel = -1;
  1226. if(maxProfile.ChargingProfileId == -1)
  1227. DEBUG_INFO("MaxProfile found.\n");
  1228. else
  1229. DEBUG_INFO("MaxProfile updated.\n");
  1230. // Required item
  1231. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1232. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1233. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1234. if(isUnitA)
  1235. {
  1236. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1237. 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++)
  1238. {
  1239. 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"));
  1240. 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?
  1241. 3:
  1242. 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")));
  1243. 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")));
  1244. }
  1245. }
  1246. else
  1247. {
  1248. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1249. 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++)
  1250. {
  1251. 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"));
  1252. 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?
  1253. 3:
  1254. 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")));
  1255. 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));
  1256. }
  1257. }
  1258. // Optional item
  1259. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1260. {
  1261. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1262. }
  1263. else
  1264. {
  1265. sprintf((char*)maxProfile.ValidFrom, " ");
  1266. }
  1267. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1268. {
  1269. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1270. }
  1271. else
  1272. {
  1273. sprintf((char*)maxProfile.ValidTo, " ");
  1274. }
  1275. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1276. {
  1277. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1278. }
  1279. else
  1280. {
  1281. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1282. }
  1283. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1284. {
  1285. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1286. }
  1287. else
  1288. {
  1289. maxProfile.TransactionId = -1;
  1290. }
  1291. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1292. {
  1293. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1294. }
  1295. else
  1296. {
  1297. maxProfile.ChargingSchedule.Duration = 86400;
  1298. }
  1299. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1300. {
  1301. 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")));
  1302. }
  1303. else
  1304. {
  1305. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1306. }
  1307. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1308. {
  1309. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1310. }
  1311. else
  1312. {
  1313. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. json_object_put(obj);
  1319. }
  1320. fclose(fp);
  1321. /*
  1322. if(maxProfile.ChargingProfileId !=-1)
  1323. {
  1324. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1325. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1326. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1327. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1328. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1329. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1330. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1331. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1332. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1333. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1334. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1335. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1336. {
  1337. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1338. {
  1339. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1340. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1341. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1342. }
  1343. }
  1344. }
  1345. else
  1346. DEBUG_INFO("MaxProfile not found.\n");
  1347. DEBUG_INFO("------------------------------------\n");*/
  1348. }
  1349. if(maxProfile.ChargingProfileId != -1)
  1350. {
  1351. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1352. {
  1353. if(maxProfile.ChargingSchedule.Duration != -1)
  1354. {
  1355. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1356. 0:
  1357. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1358. }
  1359. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1360. {
  1361. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1362. {
  1363. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1364. 0:
  1365. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1366. if(idxPeriod > 0)
  1367. {
  1368. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1369. {
  1370. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1371. }
  1372. }
  1373. }
  1374. }
  1375. }
  1376. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1377. {
  1378. if(maxProfile.ChargingSchedule.Duration != -1)
  1379. {
  1380. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1381. }
  1382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1383. {
  1384. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1385. {
  1386. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1387. if(idxPeriod > 0)
  1388. {
  1389. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1390. {
  1391. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1392. }
  1393. }
  1394. }
  1395. }
  1396. }
  1397. else
  1398. {
  1399. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1400. {
  1401. if(maxProfile.ChargingSchedule.Duration != -1)
  1402. {
  1403. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1404. 0:
  1405. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1406. }
  1407. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1408. {
  1409. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1410. {
  1411. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1412. 0:
  1413. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1414. if(idxPeriod > 0)
  1415. {
  1416. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1417. {
  1418. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1419. }
  1420. }
  1421. }
  1422. }
  1423. }
  1424. else
  1425. {
  1426. if(maxProfile.ChargingSchedule.Duration != -1)
  1427. {
  1428. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1429. 0:
  1430. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1431. }
  1432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1433. {
  1434. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1435. {
  1436. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1437. 0:
  1438. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1439. if(idxPeriod > 0)
  1440. {
  1441. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1442. {
  1443. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. }
  1450. /*
  1451. DEBUG_INFO("MaxProfile after align.\n");
  1452. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1453. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1454. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1455. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1456. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1457. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1458. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1459. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1460. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1461. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1462. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1463. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1464. {
  1465. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1466. {
  1467. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1468. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1469. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1470. }
  1471. }
  1472. DEBUG_INFO("------------------------------------\n");*/
  1473. }
  1474. // Find each profile period quantity
  1475. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1476. {
  1477. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1478. limitMax = idx+1;
  1479. }
  1480. if(maxProfile.ChargingProfileId != -1)
  1481. {
  1482. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1483. {
  1484. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1485. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1486. (maxProfile.ChargingSchedule.Duration > 0))
  1487. {
  1488. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1489. {
  1490. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1491. compositePeriodIdx++;
  1492. }
  1493. else
  1494. {
  1495. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1496. }
  1497. }
  1498. }
  1499. }
  1500. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1501. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1502. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1503. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1504. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1505. {
  1506. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1507. {
  1508. compositeProfile.ChargingProfileId = 1;
  1509. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1510. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1511. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1512. }
  1513. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1514. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1515. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1516. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1517. }
  1518. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1519. if(line)
  1520. free(line);
  1521. }
  1522. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1523. {
  1524. FILE *fp;
  1525. char profileFileName[128];
  1526. char *line = NULL;
  1527. size_t len = 0;
  1528. time_t CurrentTime;
  1529. struct tm *tmComposite;
  1530. struct StructChargingProfile maxProfile;
  1531. struct StructChargingProfile defaultTxProfile;
  1532. struct StructChargingProfile txProfile;
  1533. struct StructChargingProfile compositeProfile;
  1534. struct StructChargingSchedulePeriod tmpPeriod;
  1535. uint8_t limitMax=0;
  1536. uint8_t limitDef=0;
  1537. uint8_t limitTx=0;
  1538. int compositePeriodIdx = 0;
  1539. CurrentTime = time(NULL);
  1540. tmComposite=localtime(&CurrentTime);
  1541. 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);
  1542. if(isUnitA)
  1543. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1544. else
  1545. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1546. compositeProfile.ChargingSchedule.Duration = durationReq;
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1550. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1551. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1552. }
  1553. compositeProfile.ChargingProfileId = 0;
  1554. compositeProfile.StackLevel = 99 ;
  1555. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1556. maxProfile.ChargingProfileId = -1;
  1557. defaultTxProfile.ChargingProfileId = -1;
  1558. txProfile.ChargingProfileId = -1;
  1559. maxProfile.ChargingSchedule.Duration = -1;
  1560. defaultTxProfile.ChargingSchedule.Duration = -1;
  1561. txProfile.ChargingSchedule.Duration = -1;
  1562. system("rm -f /tmp/*.json");
  1563. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1564. /*
  1565. * Search valid charging profile
  1566. */
  1567. //DEBUG_INFO("====================================\n");
  1568. // Search tx profile
  1569. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1570. if((access(profileFileName, F_OK))!=-1)
  1571. {
  1572. fp = fopen(profileFileName, "r");
  1573. while(getline(&line, &len, fp) != -1)
  1574. {
  1575. json_object *obj = NULL;
  1576. obj = json_tokener_parse(line);
  1577. if(is_error(obj))
  1578. {
  1579. DEBUG_ERROR("Parse txProfile from file error.\n");
  1580. }
  1581. else
  1582. {
  1583. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1584. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1585. )
  1586. {
  1587. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1588. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1589. )
  1590. {
  1591. struct tm tmFrom, tmTo;
  1592. struct timeb tbFrom, tbTo;
  1593. 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) &&
  1594. (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))
  1595. {
  1596. tmFrom.tm_year -= 1900;
  1597. tmFrom.tm_mon -= 1;
  1598. tbFrom.time = mktime(&tmFrom);
  1599. tmTo.tm_year -= 1900;
  1600. tmTo.tm_mon -= 1;
  1601. tbTo.time = mktime(&tmTo);
  1602. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1603. {
  1604. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1605. {
  1606. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1607. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1608. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1609. }
  1610. txProfile.ChargingProfileId = -1;
  1611. txProfile.StackLevel = -1;
  1612. if(txProfile.ChargingProfileId == -1)
  1613. DEBUG_INFO("TxProfile found.\n");
  1614. else
  1615. DEBUG_INFO("TxProfile updated.\n");
  1616. // Required item
  1617. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1618. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1619. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1620. if(isUnitA)
  1621. {
  1622. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1623. 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++)
  1624. {
  1625. 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"));
  1626. 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?
  1627. 3:
  1628. 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")));
  1629. 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")));
  1630. }
  1631. }
  1632. else
  1633. {
  1634. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1635. 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++)
  1636. {
  1637. 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"));
  1638. 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?
  1639. 3:
  1640. 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")));
  1641. 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));
  1642. }
  1643. }
  1644. // Optional item
  1645. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1646. {
  1647. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1648. }
  1649. else
  1650. {
  1651. sprintf((char*)txProfile.ValidFrom, " ");
  1652. }
  1653. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1654. {
  1655. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1656. }
  1657. else
  1658. {
  1659. sprintf((char*)txProfile.ValidTo, " ");
  1660. }
  1661. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1662. {
  1663. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1664. }
  1665. else
  1666. {
  1667. sprintf((char*)txProfile.RecurrencyKind, " ");
  1668. }
  1669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1670. {
  1671. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1672. }
  1673. else
  1674. {
  1675. txProfile.TransactionId = -1;
  1676. }
  1677. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1678. {
  1679. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1680. }
  1681. else
  1682. {
  1683. txProfile.ChargingSchedule.Duration = 86400;
  1684. }
  1685. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1686. {
  1687. 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")));
  1688. }
  1689. else
  1690. {
  1691. 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));
  1692. }
  1693. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1694. {
  1695. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1696. }
  1697. else
  1698. {
  1699. txProfile.ChargingSchedule.MinChargingRate = -1;
  1700. }
  1701. }
  1702. }
  1703. }
  1704. else
  1705. {
  1706. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1707. {
  1708. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1709. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1710. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1711. }
  1712. txProfile.ChargingProfileId = -1;
  1713. txProfile.StackLevel = -1;
  1714. if(txProfile.ChargingProfileId == -1)
  1715. DEBUG_INFO("TxProfile found.\n");
  1716. else
  1717. DEBUG_INFO("TxProfile updated.\n");
  1718. // Required item
  1719. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1720. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1721. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1722. if(isUnitA)
  1723. {
  1724. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1725. 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++)
  1726. {
  1727. 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"));
  1728. 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?
  1729. 3:
  1730. 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")));
  1731. 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")));
  1732. }
  1733. }
  1734. else
  1735. {
  1736. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1737. 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++)
  1738. {
  1739. 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"));
  1740. 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?
  1741. 3:
  1742. 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")));
  1743. 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));
  1744. }
  1745. }
  1746. // Optional item
  1747. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1748. {
  1749. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1750. }
  1751. else
  1752. {
  1753. sprintf((char*)txProfile.ValidFrom, " ");
  1754. }
  1755. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1756. {
  1757. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1758. }
  1759. else
  1760. {
  1761. sprintf((char*)txProfile.ValidTo, " ");
  1762. }
  1763. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1764. {
  1765. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1766. }
  1767. else
  1768. {
  1769. sprintf((char*)txProfile.RecurrencyKind, " ");
  1770. }
  1771. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1772. {
  1773. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1774. }
  1775. else
  1776. {
  1777. txProfile.TransactionId = -1;
  1778. }
  1779. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1780. {
  1781. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1782. }
  1783. else
  1784. {
  1785. txProfile.ChargingSchedule.Duration = 86400;
  1786. }
  1787. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1788. {
  1789. 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")));
  1790. }
  1791. else
  1792. {
  1793. 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));
  1794. }
  1795. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1796. {
  1797. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1798. }
  1799. else
  1800. {
  1801. txProfile.ChargingSchedule.MinChargingRate = -1;
  1802. }
  1803. }
  1804. }
  1805. }
  1806. json_object_put(obj);
  1807. }
  1808. fclose(fp);
  1809. /*
  1810. if(txProfile.ChargingProfileId != -1)
  1811. {
  1812. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1813. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1814. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1815. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1816. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1817. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1818. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1819. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1820. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1821. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1822. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1823. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1824. {
  1825. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1826. {
  1827. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1828. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1829. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1830. }
  1831. }
  1832. }
  1833. else
  1834. DEBUG_INFO("TxProfile not found.\n");*/
  1835. }
  1836. // Search default tx profile
  1837. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1838. if((access(profileFileName, F_OK))==-1)
  1839. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1840. if((access(profileFileName, F_OK))!=-1)
  1841. {
  1842. fp = fopen(profileFileName, "r");
  1843. while(getline(&line, &len, fp) != -1)
  1844. {
  1845. json_object *obj = NULL;
  1846. obj = json_tokener_parse(line);
  1847. if(is_error(obj))
  1848. {
  1849. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1850. }
  1851. else
  1852. {
  1853. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1854. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1855. )
  1856. {
  1857. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1858. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1859. )
  1860. {
  1861. struct tm tmFrom, tmTo;
  1862. struct timeb tbFrom, tbTo;
  1863. 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) &&
  1864. (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))
  1865. {
  1866. tmFrom.tm_year -= 1900;
  1867. tmFrom.tm_mon -= 1;
  1868. tbFrom.time = mktime(&tmFrom);
  1869. tmTo.tm_year -= 1900;
  1870. tmTo.tm_mon -= 1;
  1871. tbTo.time = mktime(&tmTo);
  1872. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1873. {
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1877. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1878. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1879. }
  1880. defaultTxProfile.ChargingProfileId = -1;
  1881. defaultTxProfile.StackLevel = -1;
  1882. if(defaultTxProfile.ChargingProfileId == -1)
  1883. DEBUG_INFO("TxDefaultProfile found.\n");
  1884. else
  1885. DEBUG_INFO("TxDefaultProfile updated.\n");
  1886. // Required item
  1887. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1888. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1889. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1890. if(isUnitA)
  1891. {
  1892. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1893. 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++)
  1894. {
  1895. 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"));
  1896. 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?
  1897. 3:
  1898. 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")));
  1899. 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")));
  1900. }
  1901. }
  1902. else
  1903. {
  1904. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1905. 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++)
  1906. {
  1907. 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"));
  1908. 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?
  1909. 3:
  1910. 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")));
  1911. 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));
  1912. }
  1913. }
  1914. // Optional item
  1915. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1916. {
  1917. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1918. }
  1919. else
  1920. {
  1921. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1922. }
  1923. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1924. {
  1925. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1926. }
  1927. else
  1928. {
  1929. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1930. }
  1931. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1932. {
  1933. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1934. }
  1935. else
  1936. {
  1937. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1938. }
  1939. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1940. {
  1941. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1942. }
  1943. else
  1944. {
  1945. defaultTxProfile.TransactionId = -1;
  1946. }
  1947. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1948. {
  1949. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1950. }
  1951. else
  1952. {
  1953. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1954. }
  1955. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1956. {
  1957. 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")));
  1958. }
  1959. else
  1960. {
  1961. 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));
  1962. }
  1963. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1964. {
  1965. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1966. }
  1967. else
  1968. {
  1969. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1970. }
  1971. }
  1972. }
  1973. }
  1974. else
  1975. {
  1976. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1977. {
  1978. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1979. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1980. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1981. }
  1982. defaultTxProfile.ChargingProfileId = -1;
  1983. defaultTxProfile.StackLevel = -1;
  1984. if(defaultTxProfile.ChargingProfileId == -1)
  1985. DEBUG_INFO("TxDefaultProfile found.\n");
  1986. else
  1987. DEBUG_INFO("TxDefaultProfile updated.\n");
  1988. // Required item
  1989. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1990. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1991. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1992. if(isUnitA)
  1993. {
  1994. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1995. 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++)
  1996. {
  1997. 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"));
  1998. 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?
  1999. 3:
  2000. 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")));
  2001. 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")));
  2002. }
  2003. }
  2004. else
  2005. {
  2006. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2007. 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++)
  2008. {
  2009. 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"));
  2010. 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?
  2011. 3:
  2012. 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")));
  2013. 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));
  2014. }
  2015. }
  2016. // Optional item
  2017. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2018. {
  2019. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2020. }
  2021. else
  2022. {
  2023. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2024. }
  2025. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2026. {
  2027. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2028. }
  2029. else
  2030. {
  2031. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2032. }
  2033. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2034. {
  2035. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2036. }
  2037. else
  2038. {
  2039. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2040. }
  2041. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2042. {
  2043. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2044. }
  2045. else
  2046. {
  2047. defaultTxProfile.TransactionId = -1;
  2048. }
  2049. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2050. {
  2051. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2052. }
  2053. else
  2054. {
  2055. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2056. }
  2057. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2058. {
  2059. 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")));
  2060. }
  2061. else
  2062. {
  2063. 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));
  2064. }
  2065. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2066. {
  2067. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2068. }
  2069. else
  2070. {
  2071. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2072. }
  2073. }
  2074. }
  2075. }
  2076. json_object_put(obj);
  2077. }
  2078. fclose(fp);
  2079. /*
  2080. if(defaultTxProfile.ChargingProfileId != -1)
  2081. {
  2082. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2083. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2084. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2085. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2086. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2087. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2088. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2089. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2090. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2091. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2092. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2094. {
  2095. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2096. {
  2097. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2098. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2099. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2100. }
  2101. }
  2102. }
  2103. else
  2104. DEBUG_INFO("TxDefaultProfile not found.\n");
  2105. DEBUG_INFO("------------------------------------\n");*/
  2106. }
  2107. // Search max profile
  2108. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2109. if((access(profileFileName, F_OK))!=-1)
  2110. {
  2111. fp = fopen(profileFileName, "r");
  2112. while(getline(&line, &len, fp) != -1)
  2113. {
  2114. json_object *obj = NULL;
  2115. obj = json_tokener_parse(line);
  2116. if(is_error(obj))
  2117. {
  2118. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2119. }
  2120. else
  2121. {
  2122. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2123. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2124. )
  2125. {
  2126. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2127. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2128. )
  2129. {
  2130. struct tm tmFrom, tmTo;
  2131. struct timeb tbFrom, tbTo;
  2132. 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) &&
  2133. (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))
  2134. {
  2135. tmFrom.tm_year -= 1900;
  2136. tmFrom.tm_mon -= 1;
  2137. tbFrom.time = mktime(&tmFrom);
  2138. tmTo.tm_year -= 1900;
  2139. tmTo.tm_mon -= 1;
  2140. tbTo.time = mktime(&tmTo);
  2141. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2142. {
  2143. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2144. {
  2145. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2146. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2147. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2148. }
  2149. maxProfile.ChargingProfileId = -1;
  2150. maxProfile.StackLevel = -1;
  2151. if(maxProfile.ChargingProfileId == -1)
  2152. DEBUG_INFO("MaxProfile found.\n");
  2153. else
  2154. DEBUG_INFO("MaxProfile updated.\n");
  2155. // Required item
  2156. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2157. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2158. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2159. if(isUnitA)
  2160. {
  2161. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2162. 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++)
  2163. {
  2164. 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"));
  2165. 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?
  2166. 3:
  2167. 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")));
  2168. 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")));
  2169. }
  2170. }
  2171. else
  2172. {
  2173. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2174. 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++)
  2175. {
  2176. 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"));
  2177. 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?
  2178. 3:
  2179. 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")));
  2180. 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));
  2181. }
  2182. }
  2183. // Optional item
  2184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2185. {
  2186. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2187. }
  2188. else
  2189. {
  2190. sprintf((char*)maxProfile.ValidFrom, " ");
  2191. }
  2192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2193. {
  2194. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2195. }
  2196. else
  2197. {
  2198. sprintf((char*)maxProfile.ValidTo, " ");
  2199. }
  2200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2201. {
  2202. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2207. }
  2208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2209. {
  2210. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2211. }
  2212. else
  2213. {
  2214. maxProfile.TransactionId = -1;
  2215. }
  2216. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2217. {
  2218. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2219. }
  2220. else
  2221. {
  2222. maxProfile.ChargingSchedule.Duration = 86400;
  2223. }
  2224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2225. {
  2226. 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")));
  2227. }
  2228. else
  2229. {
  2230. 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));
  2231. }
  2232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2233. {
  2234. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2235. }
  2236. else
  2237. {
  2238. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2239. }
  2240. }
  2241. }
  2242. }
  2243. else
  2244. {
  2245. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2246. {
  2247. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2248. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2249. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2250. }
  2251. maxProfile.ChargingProfileId = -1;
  2252. maxProfile.StackLevel = -1;
  2253. if(maxProfile.ChargingProfileId == -1)
  2254. DEBUG_INFO("MaxProfile found.\n");
  2255. else
  2256. DEBUG_INFO("MaxProfile updated.\n");
  2257. // Required item
  2258. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2259. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2260. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2261. if(isUnitA)
  2262. {
  2263. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2264. 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++)
  2265. {
  2266. 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"));
  2267. 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?
  2268. 3:
  2269. 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")));
  2270. 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")));
  2271. }
  2272. }
  2273. else
  2274. {
  2275. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2276. 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++)
  2277. {
  2278. 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"));
  2279. 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?
  2280. 3:
  2281. 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")));
  2282. 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));
  2283. }
  2284. }
  2285. // Optional item
  2286. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2287. {
  2288. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2289. }
  2290. else
  2291. {
  2292. sprintf((char*)maxProfile.ValidFrom, " ");
  2293. }
  2294. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2295. {
  2296. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2297. }
  2298. else
  2299. {
  2300. sprintf((char*)maxProfile.ValidTo, " ");
  2301. }
  2302. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2303. {
  2304. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2305. }
  2306. else
  2307. {
  2308. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2309. }
  2310. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2311. {
  2312. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2313. }
  2314. else
  2315. {
  2316. maxProfile.TransactionId = -1;
  2317. }
  2318. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2319. {
  2320. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2321. }
  2322. else
  2323. {
  2324. maxProfile.ChargingSchedule.Duration = 86400;
  2325. }
  2326. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2327. {
  2328. 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")));
  2329. }
  2330. else
  2331. {
  2332. 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));
  2333. }
  2334. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2335. {
  2336. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2337. }
  2338. else
  2339. {
  2340. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2341. }
  2342. }
  2343. }
  2344. }
  2345. json_object_put(obj);
  2346. }
  2347. fclose(fp);
  2348. /*
  2349. if(maxProfile.ChargingProfileId !=-1)
  2350. {
  2351. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2352. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2353. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2354. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2355. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2356. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2357. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2358. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2359. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2360. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2361. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2362. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2363. {
  2364. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2365. {
  2366. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2367. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2368. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2369. }
  2370. }
  2371. }
  2372. else
  2373. DEBUG_INFO("MaxProfile not found.\n");
  2374. DEBUG_INFO("------------------------------------\n");*/
  2375. }
  2376. /*
  2377. * Align found profile start schedule & periods
  2378. */
  2379. //DEBUG_INFO("====================================\n");
  2380. /*
  2381. // For local test usage, force modify found profile start schedule info
  2382. 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);
  2383. 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);
  2384. 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);
  2385. */
  2386. if(txProfile.ChargingProfileId != -1)
  2387. {
  2388. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2389. {
  2390. if(txProfile.ChargingSchedule.Duration != -1)
  2391. {
  2392. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2393. 0:
  2394. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2395. }
  2396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2397. {
  2398. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2399. {
  2400. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2401. 0:
  2402. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2403. if(idxPeriod > 0)
  2404. {
  2405. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2406. {
  2407. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2414. {
  2415. if(txProfile.ChargingSchedule.Duration != -1)
  2416. {
  2417. 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?
  2418. 0:
  2419. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2420. }
  2421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2422. {
  2423. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2424. {
  2425. 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?
  2426. 0:
  2427. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2428. if(idxPeriod > 0)
  2429. {
  2430. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2431. {
  2432. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. else
  2439. {
  2440. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2441. {
  2442. if(txProfile.ChargingSchedule.Duration != -1)
  2443. {
  2444. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2445. 0:
  2446. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2447. }
  2448. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2449. {
  2450. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2451. {
  2452. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2453. 0:
  2454. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2455. if(idxPeriod > 0)
  2456. {
  2457. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2458. {
  2459. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. }
  2465. else
  2466. {
  2467. if(txProfile.ChargingSchedule.Duration != -1)
  2468. {
  2469. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2470. 0:
  2471. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2472. }
  2473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2474. {
  2475. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2476. {
  2477. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2478. 0:
  2479. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2480. if(idxPeriod > 0)
  2481. {
  2482. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2483. {
  2484. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2485. }
  2486. }
  2487. }
  2488. }
  2489. }
  2490. }
  2491. /*
  2492. DEBUG_INFO("txProfile after align.\n");
  2493. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2494. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2495. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2496. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2497. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2498. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2499. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2500. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2501. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2502. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2503. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2504. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2505. {
  2506. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2507. {
  2508. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2509. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2510. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2511. }
  2512. }*/
  2513. }
  2514. if(defaultTxProfile.ChargingProfileId != -1)
  2515. {
  2516. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2517. {
  2518. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2519. {
  2520. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2521. 0:
  2522. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2523. }
  2524. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2525. {
  2526. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2527. {
  2528. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2529. 0:
  2530. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2531. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2532. {
  2533. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2534. }
  2535. if(idxPeriod > 0)
  2536. {
  2537. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2538. {
  2539. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2540. }
  2541. }
  2542. }
  2543. }
  2544. }
  2545. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2546. {
  2547. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2548. {
  2549. 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?
  2550. 0:
  2551. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2552. }
  2553. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2554. {
  2555. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2556. {
  2557. 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?
  2558. 0:
  2559. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2560. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2561. {
  2562. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2563. }
  2564. if(idxPeriod > 0)
  2565. {
  2566. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2567. {
  2568. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2569. }
  2570. }
  2571. }
  2572. }
  2573. }
  2574. else
  2575. {
  2576. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2577. {
  2578. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2579. {
  2580. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2581. 0:
  2582. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2583. }
  2584. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2585. {
  2586. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2587. {
  2588. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2589. 0:
  2590. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2591. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2592. {
  2593. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2594. }
  2595. if(idxPeriod > 0)
  2596. {
  2597. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2598. {
  2599. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2600. }
  2601. }
  2602. }
  2603. }
  2604. }
  2605. else
  2606. {
  2607. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2608. {
  2609. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2610. 0:
  2611. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2612. }
  2613. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2614. {
  2615. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2616. {
  2617. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2618. 0:
  2619. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2620. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2621. {
  2622. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2623. }
  2624. if(idxPeriod > 0)
  2625. {
  2626. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2627. {
  2628. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2629. }
  2630. }
  2631. }
  2632. }
  2633. }
  2634. }
  2635. /*
  2636. DEBUG_INFO("defaultTxProfile after align.\n");
  2637. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2638. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2639. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2640. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2641. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2642. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2643. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2644. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2645. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2646. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2647. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2648. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2649. {
  2650. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2651. {
  2652. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2653. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2654. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2655. }
  2656. }
  2657. DEBUG_INFO("------------------------------------\n");*/
  2658. }
  2659. if(maxProfile.ChargingProfileId != -1)
  2660. {
  2661. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2662. {
  2663. if(maxProfile.ChargingSchedule.Duration != -1)
  2664. {
  2665. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2666. 0:
  2667. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2668. }
  2669. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2670. {
  2671. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2672. {
  2673. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2674. 0:
  2675. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2676. if(idxPeriod > 0)
  2677. {
  2678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2679. {
  2680. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2681. }
  2682. }
  2683. }
  2684. }
  2685. }
  2686. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2687. {
  2688. if(maxProfile.ChargingSchedule.Duration != -1)
  2689. {
  2690. 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?
  2691. 0:
  2692. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2693. }
  2694. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2695. {
  2696. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2697. {
  2698. 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?
  2699. 0:
  2700. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2701. if(idxPeriod > 0)
  2702. {
  2703. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2704. {
  2705. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. else
  2712. {
  2713. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2714. {
  2715. if(maxProfile.ChargingSchedule.Duration != -1)
  2716. {
  2717. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2718. 0:
  2719. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2720. }
  2721. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2722. {
  2723. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2724. {
  2725. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2726. 0:
  2727. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2728. if(idxPeriod > 0)
  2729. {
  2730. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2731. {
  2732. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2733. }
  2734. }
  2735. }
  2736. }
  2737. }
  2738. else
  2739. {
  2740. if(maxProfile.ChargingSchedule.Duration != -1)
  2741. {
  2742. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2743. 0:
  2744. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2745. }
  2746. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2747. {
  2748. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2749. {
  2750. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2751. 0:
  2752. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2753. if(idxPeriod > 0)
  2754. {
  2755. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2756. {
  2757. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2758. }
  2759. }
  2760. }
  2761. }
  2762. }
  2763. }
  2764. /*
  2765. DEBUG_INFO("MaxProfile after align.\n");
  2766. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2767. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2768. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2769. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2770. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2771. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2772. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2773. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2774. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2775. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2776. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2777. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2778. {
  2779. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2780. {
  2781. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2782. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2783. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2784. }
  2785. }
  2786. DEBUG_INFO("------------------------------------\n");*/
  2787. }
  2788. /*
  2789. * Merge to conposite schedule
  2790. */
  2791. //DEBUG_INFO("====================================\n");
  2792. // Find each profile period quantity
  2793. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2794. {
  2795. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2796. limitMax = idx+1;
  2797. }
  2798. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2799. {
  2800. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2801. limitDef = idx+1;
  2802. }
  2803. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2804. {
  2805. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2806. limitTx = idx+1;
  2807. }
  2808. // TxProfile found, composite schedule based on it
  2809. if(txProfile.ChargingProfileId != -1)
  2810. {
  2811. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2812. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2813. {
  2814. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2815. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2816. (txProfile.ChargingSchedule.Duration > 0))
  2817. {
  2818. if(maxProfile.ChargingProfileId != -1)
  2819. {
  2820. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2821. {
  2822. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2823. {
  2824. if((maxProfile.ChargingSchedule.Duration > 0))
  2825. {
  2826. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2827. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2828. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2829. }
  2830. else
  2831. {
  2832. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2833. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2834. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2835. }
  2836. }
  2837. if(idxMaxPeriod == (limitMax-1))
  2838. {
  2839. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2840. {
  2841. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2842. {
  2843. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2844. compositePeriodIdx++;
  2845. }
  2846. else
  2847. {
  2848. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. else
  2855. {
  2856. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2857. {
  2858. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2859. compositePeriodIdx++;
  2860. }
  2861. else
  2862. {
  2863. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2864. }
  2865. }
  2866. }
  2867. if(idxTxPeriod == (limitTx-1))
  2868. {
  2869. if(defaultTxProfile.ChargingProfileId != -1)
  2870. {
  2871. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  2872. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2873. {
  2874. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2875. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2876. (defaultTxProfile.ChargingSchedule.Duration>0))
  2877. {
  2878. if(maxProfile.ChargingProfileId != -1)
  2879. {
  2880. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2881. {
  2882. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2883. {
  2884. if((maxProfile.ChargingSchedule.Duration > 0))
  2885. {
  2886. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2887. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2888. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2889. }
  2890. else
  2891. {
  2892. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2893. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2894. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2895. }
  2896. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2897. {
  2898. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2899. {
  2900. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2901. compositePeriodIdx++;
  2902. }
  2903. else
  2904. {
  2905. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2906. }
  2907. }
  2908. // Delete duplicate period
  2909. if(compositePeriodIdx > 1)
  2910. {
  2911. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2912. {
  2913. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2914. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2915. compositePeriodIdx -= 1;
  2916. }
  2917. }
  2918. }
  2919. else
  2920. {
  2921. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2922. {
  2923. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2924. compositePeriodIdx++;
  2925. }
  2926. else
  2927. {
  2928. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2929. }
  2930. break;
  2931. }
  2932. }
  2933. }
  2934. else
  2935. {
  2936. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2937. {
  2938. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2939. compositePeriodIdx++;
  2940. }
  2941. else
  2942. {
  2943. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. }
  2951. }
  2952. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2953. else if(defaultTxProfile.ChargingProfileId != -1)
  2954. {
  2955. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2956. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2957. {
  2958. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2959. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2960. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2961. {
  2962. if(maxProfile.ChargingProfileId != -1)
  2963. {
  2964. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2965. {
  2966. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2967. {
  2968. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2969. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2970. if((maxProfile.ChargingSchedule.Duration > 0))
  2971. {
  2972. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2973. }
  2974. else
  2975. {
  2976. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2977. }
  2978. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2979. {
  2980. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2981. {
  2982. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2983. compositePeriodIdx++;
  2984. }
  2985. else
  2986. {
  2987. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2988. }
  2989. }
  2990. // Delete duplicate period
  2991. if(compositePeriodIdx > 1)
  2992. {
  2993. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2994. {
  2995. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2996. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2997. compositePeriodIdx -= 1;
  2998. }
  2999. }
  3000. }
  3001. else
  3002. {
  3003. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3004. {
  3005. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3006. compositePeriodIdx++;
  3007. }
  3008. else
  3009. {
  3010. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3011. }
  3012. break;
  3013. }
  3014. }
  3015. }
  3016. else
  3017. {
  3018. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3019. {
  3020. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3021. compositePeriodIdx++;
  3022. }
  3023. else
  3024. {
  3025. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3026. }
  3027. }
  3028. }
  3029. }
  3030. }
  3031. // Fill other period by MaxProfile
  3032. if(maxProfile.ChargingProfileId != -1)
  3033. {
  3034. if(compositePeriodIdx==0)
  3035. {
  3036. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3037. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3038. {
  3039. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3040. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3041. (maxProfile.ChargingSchedule.Duration > 0))
  3042. {
  3043. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3044. {
  3045. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3046. compositePeriodIdx++;
  3047. }
  3048. else
  3049. {
  3050. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3051. }
  3052. }
  3053. }
  3054. }
  3055. else
  3056. {
  3057. int lastCompositePeriodIdx = compositePeriodIdx;
  3058. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3059. {
  3060. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3061. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3062. (maxProfile.ChargingSchedule.Duration > 0))
  3063. {
  3064. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3065. {
  3066. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3067. {
  3068. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3069. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3070. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3071. }
  3072. else
  3073. {
  3074. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3075. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3076. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3077. }
  3078. }
  3079. if(tmpPeriod.Limit != -1)
  3080. {
  3081. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3082. {
  3083. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3084. {
  3085. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3086. compositePeriodIdx++;
  3087. }
  3088. else
  3089. {
  3090. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3091. }
  3092. }
  3093. // Delete duplicate period
  3094. if(compositePeriodIdx > 1)
  3095. {
  3096. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3097. {
  3098. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3099. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3100. compositePeriodIdx -= 1;
  3101. }
  3102. }
  3103. }
  3104. }
  3105. }
  3106. }
  3107. }
  3108. compositeProfile.ChargingSchedule.Duration = durationReq;
  3109. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3110. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3111. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3112. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3113. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3114. {
  3115. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3116. {
  3117. compositeProfile.ChargingProfileId = 1;
  3118. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3119. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3120. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3121. }
  3122. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3123. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3124. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3125. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3126. }
  3127. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3128. if(line)
  3129. free(line);
  3130. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3131. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3132. }
  3133. //==========================================
  3134. // Init all share memory
  3135. //==========================================
  3136. int InitShareMemory()
  3137. {
  3138. int result = PASS;
  3139. int MeterSMId;
  3140. //creat ShmSysConfigAndInfo
  3141. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3142. {
  3143. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3144. result = FAIL;
  3145. }
  3146. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3147. {
  3148. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3149. result = FAIL;
  3150. }
  3151. else
  3152. {}
  3153. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3154. {
  3155. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3156. result = FAIL;
  3157. }
  3158. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3159. {
  3160. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3161. result = FAIL;
  3162. }
  3163. else
  3164. {}
  3165. //creat ShmPsuData
  3166. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3167. {
  3168. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3169. result = FAIL;
  3170. }
  3171. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3172. {
  3173. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3174. result = FAIL;
  3175. }
  3176. else
  3177. {}
  3178. //link ShmOCPP16Data
  3179. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3180. {
  3181. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3182. result = FAIL;
  3183. }
  3184. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3185. {
  3186. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3187. result = FAIL;
  3188. }
  3189. else
  3190. {}
  3191. //creat ShmOCPP16DataPH
  3192. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3193. {
  3194. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3195. result = FAIL;
  3196. }
  3197. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3198. {
  3199. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3200. result = FAIL;
  3201. }
  3202. else
  3203. {}
  3204. /****************************** For Initial Settings************************************************/
  3205. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3206. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3207. // allocate Configuration memory address
  3208. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3209. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3210. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3211. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3212. //offline MeterValue Interval
  3213. TempMeterValueInterval = 0;
  3214. return result;
  3215. }
  3216. int ProcessShareMemory()
  3217. {
  3218. int result = PASS;
  3219. if(InitShareMemory() == FAIL)
  3220. {
  3221. DEBUG_ERROR("InitShareMemory NG\n");
  3222. if(ShmStatusCodeData!=NULL)
  3223. {
  3224. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3225. }
  3226. result = FAIL;
  3227. }
  3228. // Model name parsing
  3229. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3230. {
  3231. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3232. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3233. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3234. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3235. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3236. ) // 'D' means DC
  3237. {
  3238. // DO series
  3239. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3240. {
  3241. SystemInitial += 1;
  3242. gunTotalNumber += 1;
  3243. gunType[gun_index] = GUN_TYPE_DO;
  3244. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3245. {
  3246. case Gun_Type_Chademo:
  3247. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3248. break;
  3249. case Gun_Type_CCS_2:
  3250. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3251. break;
  3252. case Gun_Type_GB:
  3253. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3254. break;
  3255. case Gun_Type_AC:
  3256. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3257. break;
  3258. default:
  3259. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3260. break;
  3261. }
  3262. }
  3263. }
  3264. else
  3265. {
  3266. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3267. {
  3268. SystemInitial += 1;
  3269. gunTotalNumber += 1;
  3270. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3271. {
  3272. case Gun_Type_Chademo:
  3273. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3274. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3275. break;
  3276. case Gun_Type_CCS_2:
  3277. gunType[gun_index] = GUN_TYPE_CCS;
  3278. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3279. break;
  3280. case Gun_Type_GB:
  3281. gunType[gun_index] = GUN_TYPE_GBT;
  3282. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3283. break;
  3284. case Gun_Type_AC:
  3285. gunType[gun_index] = GUN_TYPE_AC;
  3286. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3287. break;
  3288. default:
  3289. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3290. break;
  3291. }
  3292. }
  3293. }
  3294. }
  3295. else
  3296. {
  3297. DEBUG_ERROR("Model name parsing fail.\n");
  3298. result = FAIL;
  3299. }
  3300. if(result != PASS)sleep(5);
  3301. return result;
  3302. }
  3303. void checkRemoteStart(uint8_t connectorIdInt)
  3304. {
  3305. uint8_t tempIndex;
  3306. int result = PASS;
  3307. char cmdBuf[512];
  3308. //check Transaction active
  3309. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3310. {
  3311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3312. {
  3313. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3314. }
  3315. else
  3316. {
  3317. tempIndex = connectorIdInt -1;
  3318. }
  3319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3320. {
  3321. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3322. {
  3323. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3324. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3325. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3326. {
  3327. //Reserved
  3328. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3329. }
  3330. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3331. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3332. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3333. {
  3334. //Reserved
  3335. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3336. result = FAIL;
  3337. goto end;
  3338. }
  3339. else
  3340. {
  3341. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3342. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3343. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3344. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3345. {
  3346. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3347. result = FAIL;
  3348. goto end;
  3349. }
  3350. }//END FOR ELSE
  3351. }
  3352. }// END FOR CHAdeMO_QUANTITY
  3353. }
  3354. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3355. {
  3356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3357. {
  3358. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3359. }
  3360. else
  3361. {
  3362. tempIndex = connectorIdInt -1;
  3363. }
  3364. for (int index = 0; index < CCS_QUANTITY; index++)
  3365. {
  3366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3367. {
  3368. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3369. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3370. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3371. {
  3372. //Reserved
  3373. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3374. }
  3375. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3376. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3377. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3378. {
  3379. //Reserved
  3380. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3381. result = FAIL;
  3382. goto end;
  3383. }
  3384. else
  3385. {
  3386. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3387. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3388. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3389. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3390. {
  3391. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3392. result = FAIL;
  3393. goto end;
  3394. }
  3395. }// END FOR ELSE
  3396. }
  3397. }// END FOR CCS_QUANTITY
  3398. }
  3399. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3400. {
  3401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3402. {
  3403. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3404. }
  3405. else
  3406. {
  3407. tempIndex = connectorIdInt -1;
  3408. }
  3409. for (int index = 0; index < GB_QUANTITY; index++)
  3410. {
  3411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3412. {
  3413. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3414. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3415. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3416. {
  3417. //Reserved
  3418. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3419. }
  3420. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3421. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3422. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3423. {
  3424. //Reserved
  3425. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3426. result = FAIL;
  3427. goto end;
  3428. }
  3429. else
  3430. {
  3431. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3432. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3433. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3434. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3435. {
  3436. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3437. result = FAIL;
  3438. goto end;
  3439. }
  3440. }// END FOR ELSE
  3441. }
  3442. } // END FOR GB_QUANTITY
  3443. }
  3444. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3445. {
  3446. tempIndex = connectorIdInt -1;
  3447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3448. {
  3449. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3450. {
  3451. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3452. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3453. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3454. {
  3455. //Reserved
  3456. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3457. }
  3458. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3459. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3460. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3461. {
  3462. //Reserved
  3463. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3464. result = FAIL;
  3465. goto end;
  3466. }
  3467. else
  3468. {
  3469. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3470. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3471. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3472. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3473. {
  3474. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3475. result = FAIL;
  3476. goto end;
  3477. }
  3478. }// END FOR ELSE
  3479. }
  3480. } // END FOR GB_QUANTITY
  3481. }
  3482. else
  3483. {
  3484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3485. {
  3486. tempIndex = 2;
  3487. }
  3488. else
  3489. {
  3490. tempIndex = connectorIdInt -1;
  3491. }
  3492. for (int index = 0; index < AC_QUANTITY; index++)
  3493. {
  3494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3495. {
  3496. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3497. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3498. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3499. {
  3500. //Reserved
  3501. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3502. }
  3503. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3504. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3505. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3506. {
  3507. //Reserved
  3508. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3509. result = FAIL;
  3510. goto end;
  3511. }
  3512. else
  3513. {
  3514. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3515. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3516. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3517. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3518. {
  3519. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3520. result = FAIL;
  3521. goto end;
  3522. }
  3523. }//END FOR ELSE
  3524. }
  3525. }// END FOR AC_QUANTITY
  3526. }
  3527. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3528. {
  3529. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3530. {
  3531. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3532. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3533. {
  3534. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3535. system(cmdBuf);
  3536. }
  3537. }
  3538. else
  3539. {
  3540. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3541. result = FAIL;
  3542. }
  3543. }
  3544. end:
  3545. if(result == PASS)
  3546. {
  3547. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3548. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3549. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3550. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3551. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3552. }
  3553. }
  3554. void CheckSystemValue(void)
  3555. {
  3556. char filenmae[100]={0};
  3557. char str[100]={0};
  3558. int tempIndex = 0;
  3559. //===============================
  3560. // send Heartbeat
  3561. //===============================
  3562. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3563. {
  3564. //parameter for test
  3565. sendHeartbeatRequest(0);
  3566. //==============================================
  3567. // Reset Waiting Time
  3568. //==============================================
  3569. HeartBeatWithNOResponse += 2;
  3570. }
  3571. //===============================
  3572. // Credit deduct report
  3573. //===============================
  3574. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3575. {
  3576. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3577. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3578. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3579. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3580. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3581. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3582. }
  3583. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3584. {
  3585. OCPP_query_deduct_info();
  3586. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3587. }
  3588. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3589. {
  3590. // ClockAlign MeterValue
  3591. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3592. {
  3593. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3594. {
  3595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3596. {
  3597. tempIndex = ((gun_index==2) ? 1: 0);
  3598. }
  3599. else
  3600. {
  3601. tempIndex = gun_index;
  3602. }
  3603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3604. {
  3605. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3606. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3607. {
  3608. reqClockAlignMeter[gun_index] = 1;
  3609. }
  3610. }// End for CHAdeMO
  3611. }
  3612. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3613. {
  3614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3615. {
  3616. tempIndex = ((gun_index==2) ? 1: 0);
  3617. }
  3618. else
  3619. {
  3620. tempIndex = gun_index;
  3621. }
  3622. for (int index = 0; index < CCS_QUANTITY; index++)
  3623. {
  3624. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3625. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3626. {
  3627. reqClockAlignMeter[gun_index] = 1;
  3628. }
  3629. } // End for CCS
  3630. }
  3631. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3632. {
  3633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3634. {
  3635. tempIndex = ((gun_index==2) ? 1: 0);
  3636. }
  3637. else
  3638. {
  3639. tempIndex = gun_index;
  3640. }
  3641. for (int index = 0; index < GB_QUANTITY; index++)
  3642. {
  3643. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3644. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3645. {
  3646. reqClockAlignMeter[gun_index] = 1;
  3647. }
  3648. }// End for GB
  3649. }
  3650. else if(gunType[gun_index] == GUN_TYPE_DO)
  3651. {
  3652. tempIndex = gun_index;
  3653. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3654. {
  3655. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3656. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3657. {
  3658. reqClockAlignMeter[gun_index] = 1;
  3659. }
  3660. }
  3661. }
  3662. else
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3665. {
  3666. tempIndex = 2;
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < AC_QUANTITY; index++)
  3673. {
  3674. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3675. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3676. {
  3677. reqClockAlignMeter[gun_index] = 1;
  3678. }
  3679. }//End for AC
  3680. }
  3681. }
  3682. }
  3683. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3684. {
  3685. //==========================================
  3686. // Check remote start without connector id
  3687. //==========================================
  3688. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3689. {
  3690. int connectorIdInt = -1;
  3691. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3692. {
  3693. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3694. {
  3695. connectorIdInt = (gun_index+1);
  3696. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3697. checkRemoteStart(connectorIdInt);
  3698. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3699. break;
  3700. }
  3701. }
  3702. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3703. {
  3704. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3705. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3706. }
  3707. }
  3708. //==========================================
  3709. // csu trigger DataTransferReq
  3710. //==========================================
  3711. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3712. {
  3713. sendDataTransferRequest(gun_index);
  3714. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3715. }
  3716. //===============================
  3717. // CSU Trigger Authorize Request
  3718. //===============================
  3719. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3720. {
  3721. sendAuthorizeRequest(0);
  3722. authorizeRetryTimes = authorizeRetryTimes + 1;
  3723. if(authorizeRetryTimes < 3)
  3724. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3725. }
  3726. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3727. {
  3728. authorizeRetryTimes = 0;
  3729. SetOcppConnStatus(FALSE);
  3730. server_sign = FALSE;
  3731. }
  3732. 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))
  3733. {
  3734. sendAuthorizeRequest(0);
  3735. }
  3736. //==============================================
  3737. // Charger start transaction
  3738. //==============================================
  3739. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3740. {
  3741. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3742. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3743. sendStartTransactionRequest(gun_index);
  3744. refreshStartTimer(&clientTime.StartTransaction);
  3745. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3746. //storeTempStopTransaction(gun_index);
  3747. }
  3748. //==============================================
  3749. // Charger stop transaction
  3750. //==============================================
  3751. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3752. {
  3753. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3754. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3755. sendStopTransactionRequest(gun_index);
  3756. refreshStartTimer(&clientTime.StopTransaction);
  3757. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3758. }
  3759. //==============================================
  3760. // Charger status report
  3761. //==============================================
  3762. //--- Check Mode Change ---//
  3763. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3764. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3765. {
  3766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3767. {
  3768. tempIndex = ((gun_index==2) ? 1: 0);
  3769. }
  3770. else
  3771. {
  3772. tempIndex = gun_index;
  3773. }
  3774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3775. {
  3776. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3777. {
  3778. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3779. {
  3780. // Sent unplug message for California pricing logic
  3781. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3782. {
  3783. uint8_t ts[20];
  3784. getNowDatetime(ts);
  3785. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3786. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3787. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3788. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3789. }
  3790. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3791. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3792. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3793. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3794. {
  3795. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3796. if((access(filenmae,F_OK))!=-1)
  3797. {
  3798. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3799. sprintf(str,"rm -f %s",filenmae);
  3800. system(str);
  3801. }
  3802. }
  3803. }
  3804. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3805. #if 1 // for TempStopTransaction
  3806. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3807. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3808. {
  3809. checkTempStopTransaction(gun_index);
  3810. }
  3811. #endif
  3812. }
  3813. }
  3814. }
  3815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3816. {
  3817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3818. {
  3819. tempIndex = ((gun_index==2) ? 1: 0);
  3820. }
  3821. else
  3822. {
  3823. tempIndex = gun_index;
  3824. }
  3825. for (int index = 0; index < CCS_QUANTITY; index++)
  3826. {
  3827. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3828. {
  3829. 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]*/ )
  3830. {
  3831. // Sent unplug message for California pricing logic
  3832. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3833. {
  3834. uint8_t ts[20];
  3835. getNowDatetime(ts);
  3836. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3837. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3838. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3839. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3840. }
  3841. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3842. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3843. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3844. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3845. {
  3846. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3847. if((access(filenmae,F_OK))!=-1)
  3848. {
  3849. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3850. sprintf(str,"rm -f %s",filenmae);
  3851. system(str);
  3852. }
  3853. }
  3854. }
  3855. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3856. #if 1 // for TempStopTransaction
  3857. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3858. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3859. {
  3860. checkTempStopTransaction(gun_index);
  3861. }
  3862. #endif
  3863. }
  3864. }
  3865. }
  3866. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3867. {
  3868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3869. {
  3870. tempIndex = ((gun_index==2) ? 1: 0);
  3871. }
  3872. else
  3873. {
  3874. tempIndex = gun_index;
  3875. }
  3876. for (int index = 0; index < GB_QUANTITY; index++)
  3877. {
  3878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3879. {
  3880. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3881. {
  3882. // Sent unplug message for California pricing logic
  3883. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3884. {
  3885. uint8_t ts[20];
  3886. getNowDatetime(ts);
  3887. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3888. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3889. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3890. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3891. }
  3892. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3893. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3894. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3895. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3896. {
  3897. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3898. if((access(filenmae,F_OK))!=-1)
  3899. {
  3900. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3901. sprintf(str,"rm -f %s",filenmae);
  3902. system(str);
  3903. }
  3904. }
  3905. }
  3906. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3907. #if 1 // for TempStopTransaction
  3908. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3909. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3910. {
  3911. checkTempStopTransaction(gun_index);
  3912. }
  3913. #endif
  3914. }
  3915. }
  3916. }
  3917. else if(gunType[gun_index] == GUN_TYPE_DO)
  3918. {
  3919. tempIndex = gun_index;
  3920. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3921. {
  3922. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3923. {
  3924. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3925. {
  3926. // Sent unplug message for California pricing logic
  3927. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3928. {
  3929. uint8_t ts[20];
  3930. getNowDatetime(ts);
  3931. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3932. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3933. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3934. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3935. }
  3936. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3937. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3938. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3939. 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
  3940. {
  3941. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3942. if((access(filenmae,F_OK))!=-1)
  3943. {
  3944. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3945. sprintf(str,"rm -f %s",filenmae);
  3946. system(str);
  3947. }
  3948. }
  3949. }
  3950. 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);
  3951. #if 1 // for TempStopTransaction
  3952. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3953. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3954. {
  3955. checkTempStopTransaction(gun_index);
  3956. }
  3957. #endif
  3958. }
  3959. }
  3960. }
  3961. else
  3962. {
  3963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3964. {
  3965. tempIndex = 2;
  3966. }
  3967. else
  3968. {
  3969. tempIndex = gun_index;
  3970. }
  3971. for (int index = 0; index < AC_QUANTITY; index++)
  3972. {
  3973. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3974. {
  3975. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3976. {
  3977. // Sent unplug message for California pricing logic
  3978. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3979. {
  3980. uint8_t ts[20];
  3981. getNowDatetime(ts);
  3982. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3983. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3984. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3985. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3986. }
  3987. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3988. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3989. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3990. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3991. {
  3992. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3993. if((access(filenmae,F_OK))!=-1)
  3994. {
  3995. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3996. sprintf(str,"rm -f %s",filenmae);
  3997. system(str);
  3998. }
  3999. }
  4000. }
  4001. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4002. #if 1 // for TempStopTransaction
  4003. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4004. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4005. {
  4006. checkTempStopTransaction(gun_index);
  4007. }
  4008. #endif
  4009. }
  4010. }// END
  4011. }
  4012. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4013. (
  4014. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4015. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4016. )
  4017. )
  4018. {
  4019. if(SystemInitial > 0)
  4020. SystemInitial -= 1;
  4021. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4022. sendStatusNotificationRequest(gun_index);
  4023. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4024. }
  4025. //==============================================
  4026. // CSU Trigger Smart Charging Profilw
  4027. //==============================================
  4028. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4029. {
  4030. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4031. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4032. }
  4033. //==============================================
  4034. // Meter report
  4035. //==============================================
  4036. // Trigger MeterValue
  4037. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4038. {
  4039. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4040. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4041. }
  4042. // Clock-aligned Meter value
  4043. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4044. {
  4045. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4046. reqClockAlignMeter[gun_index] = 0;
  4047. }
  4048. // Sample period MeterValue
  4049. 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))))
  4050. {
  4051. //check Transaction active
  4052. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4053. {
  4054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4055. {
  4056. tempIndex = ((gun_index==2) ? 1: 0);
  4057. }
  4058. else
  4059. {
  4060. tempIndex = gun_index;
  4061. }
  4062. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4063. {
  4064. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4065. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4066. {
  4067. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4068. {
  4069. reqSampleMeter[gun_index] = 1;
  4070. }
  4071. }
  4072. }// End for CHAdeMO
  4073. }
  4074. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4075. {
  4076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4077. {
  4078. tempIndex = ((gun_index==2) ? 1: 0);
  4079. }
  4080. else
  4081. {
  4082. tempIndex = gun_index;
  4083. }
  4084. for (int index = 0; index < CCS_QUANTITY; index++)
  4085. {
  4086. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4087. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4088. {
  4089. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4090. {
  4091. reqSampleMeter[gun_index] = 1;
  4092. }
  4093. }
  4094. } // End for CCS
  4095. }
  4096. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4097. {
  4098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4099. {
  4100. tempIndex = ((gun_index==2) ? 1: 0);
  4101. }
  4102. else
  4103. {
  4104. tempIndex = gun_index;
  4105. }
  4106. for (int index = 0; index < GB_QUANTITY; index++)
  4107. {
  4108. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4109. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4112. {
  4113. reqSampleMeter[gun_index] = 1;
  4114. }
  4115. }
  4116. }// End for GB
  4117. }
  4118. else if(gunType[gun_index] == GUN_TYPE_DO)
  4119. {
  4120. tempIndex = gun_index;
  4121. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4122. {
  4123. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4124. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4125. {
  4126. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4127. {
  4128. reqSampleMeter[gun_index] = 1;
  4129. }
  4130. }
  4131. }
  4132. }
  4133. else
  4134. {
  4135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4136. {
  4137. tempIndex = 2;
  4138. }
  4139. else
  4140. {
  4141. tempIndex = gun_index;
  4142. }
  4143. for (int index = 0; index < AC_QUANTITY; index++)
  4144. {
  4145. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4146. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4147. {
  4148. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4149. {
  4150. reqSampleMeter[gun_index] = 1;
  4151. }
  4152. }
  4153. }//End for AC
  4154. }
  4155. if(reqSampleMeter[gun_index] == 1)
  4156. {
  4157. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4158. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4159. //storeTempStopTransaction(gun_index);
  4160. reqSampleMeter[gun_index] = 0;
  4161. }
  4162. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4163. }
  4164. //==============================================
  4165. // Check Connector reserved
  4166. //==============================================
  4167. //===============================
  4168. // Check if Reserve is expired
  4169. //===============================
  4170. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4171. {
  4172. double diff_t;
  4173. struct tm tp;
  4174. // current time
  4175. time_t t = time(NULL);
  4176. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4177. tp.tm_isdst = -1;
  4178. time_t utc = mktime(&tp);
  4179. diff_t = difftime(utc, t);
  4180. if(diff_t <= 0)
  4181. {
  4182. DEBUG_INFO("reserve expired.\n");
  4183. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4184. }
  4185. }//END OF Check if Reserve is expired
  4186. //==========================================
  4187. // csu trigger FirmwareStatusNotificationReq
  4188. //==========================================
  4189. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4190. {
  4191. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4192. }
  4193. //==========================================
  4194. // csu trigger DiagnosticsStatusNotificationReq
  4195. //==========================================
  4196. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4197. {
  4198. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4199. }
  4200. //==========================================
  4201. // csu trigger CancelReservationConf
  4202. //==========================================
  4203. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4204. {
  4205. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4206. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4207. }
  4208. //==========================================
  4209. // csu trigger ChangeAvailabilityConf
  4210. //==========================================
  4211. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4212. {
  4213. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4214. }
  4215. //==========================================
  4216. // csu trigger UnlockConnectorConf
  4217. //==========================================
  4218. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4219. {
  4220. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4221. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4222. }
  4223. //==========================================
  4224. // csu trigger ReserveNowConf
  4225. //==========================================
  4226. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4227. {
  4228. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4229. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4230. }
  4231. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4232. {
  4233. sendSignCertificateRequest();
  4234. }
  4235. }
  4236. }
  4237. //==========================================
  4238. // send request routine
  4239. //==========================================
  4240. int sendAuthorizeRequest(int gun_index)
  4241. {
  4242. mtrace();
  4243. int result = FAIL;
  4244. char message[100]={0};
  4245. char guid[37];
  4246. char tempdata[65]={0};
  4247. DEBUG_INFO("sendAuthorizeRequest...\n");
  4248. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4249. //Local Authorize
  4250. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4251. {
  4252. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4253. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4254. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4255. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4256. result = PASS;
  4257. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4258. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4259. authorizeRetryTimes = 0;
  4260. return result;
  4261. }
  4262. 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))||
  4263. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4264. {
  4265. // Query from cache
  4266. DEBUG_INFO("Authorize from cache.\n");
  4267. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4268. // Query from list
  4269. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4270. {
  4271. DEBUG_INFO("Authorize from list.\n");
  4272. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4273. }
  4274. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4275. {
  4276. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4277. {
  4278. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4279. }
  4280. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4281. {
  4282. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4283. }
  4284. if(!GetOcppConnStatus())
  4285. {
  4286. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4287. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4288. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4289. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4290. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4291. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4292. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4293. authorizeRetryTimes = 0;
  4294. return result;
  4295. }
  4296. }
  4297. else
  4298. {
  4299. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4300. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4301. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4302. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4303. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4304. else
  4305. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4306. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4307. result = PASS;
  4308. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4309. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4310. authorizeRetryTimes = 0;
  4311. return result;
  4312. }
  4313. }
  4314. //initialize struct Authorize
  4315. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4316. //get data from shared memory
  4317. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4318. random_uuid(guid);
  4319. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4320. LWS_Send(message);
  4321. sprintf(tempdata, "Authorize,%d", gun_index);
  4322. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4323. {
  4324. result = PASS;
  4325. DEBUG_INFO("Authorize mapItem pass\n");
  4326. }
  4327. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4328. return result;
  4329. }
  4330. int sendBootNotificationRequest(void)
  4331. {
  4332. mtrace();
  4333. int result = FAIL;
  4334. char message[500]={0}, payload[700]={0};
  4335. char guid[37]={0};
  4336. char tempdata[65]={0};
  4337. // Fill BootNotification fields
  4338. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4339. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4340. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4341. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4342. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4343. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4344. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4345. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4346. ShmOCPP16DataPH->ChargeBoxId
  4347. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4348. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4349. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4350. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4351. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4352. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4353. random_uuid(guid);
  4354. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4355. LWS_Send(message);
  4356. sprintf(tempdata, "BootNotification,0");
  4357. 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*/)
  4358. {
  4359. result = PASS;
  4360. }
  4361. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4362. strcpy(queuedata,message);
  4363. return result;
  4364. }
  4365. int sendDataTransferRequest(int gun_index)
  4366. {
  4367. mtrace();
  4368. char message[1000]={0};
  4369. char guid[37]={0};
  4370. char tempdata[65]={0};
  4371. int result = FAIL;
  4372. random_uuid(guid);
  4373. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4374. MESSAGE_TYPE_CALL,
  4375. guid,
  4376. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4377. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4378. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4379. LWS_Send(message);
  4380. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4381. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4382. {
  4383. result = PASS;
  4384. DEBUG_INFO("DataTransfer mapItem pass\n");
  4385. }
  4386. return result;
  4387. }
  4388. int sendDiagnosticsStatusNotificationRequest(char *status)
  4389. {
  4390. mtrace();
  4391. int result = FAIL;
  4392. char message[110]={0};
  4393. char guid[37]={0};
  4394. char tempdata[65]={0};
  4395. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4396. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4397. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4398. random_uuid(guid);
  4399. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4400. LWS_SendNow(message);
  4401. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4402. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4403. {
  4404. result = PASS;
  4405. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4406. }
  4407. //#ifdef SystemLogMessage
  4408. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4409. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4410. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4411. //#endif
  4412. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4413. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4414. //record status
  4415. if(strcmp(status,"Idle")==0)
  4416. {
  4417. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4418. }
  4419. else if(strcmp(status,"Uploaded")==0)
  4420. {
  4421. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4422. }
  4423. else if(strcmp(status,"UploadFailed")==0)
  4424. {
  4425. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4426. }
  4427. else if(strcmp(status,"Uploading")==0)
  4428. {
  4429. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4430. }
  4431. return result;
  4432. }
  4433. int sendFirmwareStatusNotificationRequest(char *status)
  4434. {
  4435. mtrace();
  4436. int result = FAIL;
  4437. char message[110]={0};
  4438. char guid[37]={0};
  4439. char tempdata[65]={0};
  4440. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4441. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4442. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4443. random_uuid(guid);
  4444. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4445. LWS_SendNow(message);
  4446. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4447. 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*/)
  4448. {
  4449. result = PASS;
  4450. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4451. }
  4452. //#ifdef SystemLogMessage
  4453. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4454. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4455. //#endif
  4456. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4457. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4458. //record status
  4459. if(strcmp(status,"Downloaded")==0)
  4460. {
  4461. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4462. }
  4463. else if(strcmp(status,"DownloadFailed")==0)
  4464. {
  4465. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4466. }
  4467. else if(strcmp(status,"Downloading")==0)
  4468. {
  4469. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4470. }
  4471. else if(strcmp(status,"Idle")==0)
  4472. {
  4473. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4474. }
  4475. else if(strcmp(status,"InstallationFailed")==0)
  4476. {
  4477. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4478. }
  4479. else if(strcmp(status,"Installing")==0)
  4480. {
  4481. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4482. }
  4483. else if(strcmp(status,"Installed")==0)
  4484. {
  4485. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4486. }
  4487. return result;
  4488. }
  4489. int sendHeartbeatRequest(int gun_index)
  4490. {
  4491. mtrace();
  4492. int result = FAIL;
  4493. char message[80]={0};
  4494. char guid[37]={0};
  4495. char tempdata[65]={0};
  4496. random_uuid(guid);
  4497. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4498. , MESSAGE_TYPE_CALL
  4499. , guid );
  4500. LWS_Send(message);
  4501. sprintf(tempdata, "Heartbeat,%d", 0);
  4502. 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*/)
  4503. {
  4504. result = PASS;
  4505. }
  4506. return result;
  4507. }
  4508. int sendStartTransactionRequest(int gun_index)
  4509. {
  4510. mtrace();
  4511. int result = FAIL;
  4512. char message[250]={0};
  4513. char guid[37]={0};
  4514. struct timeval tmnow;
  4515. struct tm *tm;
  4516. char buf[28];//, usec_buf[6];
  4517. char tempdata[65]={0};
  4518. int tempIndex = 0;
  4519. DEBUG_INFO("sendStartTransactionRequest...\n");
  4520. gettimeofday(&tmnow, NULL);
  4521. time_t t;
  4522. t = time(NULL);
  4523. /*UTC time and date*/
  4524. tm = gmtime(&t);
  4525. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4526. #if 0 // remove temporally
  4527. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4528. strcat(buf,".");
  4529. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4530. strcat(buf,usec_buf);
  4531. #endif
  4532. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4533. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4534. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4535. // clear StartTransaction Response
  4536. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4537. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4538. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4539. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4540. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4541. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4542. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4543. {
  4544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4545. {
  4546. tempIndex = ((gun_index==2) ? 1: 0);
  4547. }
  4548. else
  4549. {
  4550. tempIndex = gun_index;
  4551. }
  4552. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4553. {
  4554. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4555. {
  4556. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4557. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4558. }
  4559. }
  4560. }
  4561. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4562. {
  4563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4564. {
  4565. tempIndex = ((gun_index==2) ? 1: 0);
  4566. }
  4567. else
  4568. {
  4569. tempIndex = gun_index;
  4570. }
  4571. for (int index = 0; index < CCS_QUANTITY; index++)
  4572. {
  4573. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4574. {
  4575. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4576. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4577. }
  4578. }
  4579. }
  4580. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4581. {
  4582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4583. {
  4584. tempIndex = ((gun_index==2) ? 1: 0);
  4585. }
  4586. else
  4587. {
  4588. tempIndex = gun_index;
  4589. }
  4590. for (int index = 0; index < GB_QUANTITY; index++)
  4591. {
  4592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4593. {
  4594. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4595. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4596. }
  4597. }
  4598. }
  4599. else if(gunType[gun_index] == GUN_TYPE_DO)
  4600. {
  4601. tempIndex = gun_index;
  4602. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4603. {
  4604. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4605. {
  4606. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4607. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4608. }
  4609. }
  4610. }
  4611. else
  4612. {
  4613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4614. {
  4615. tempIndex = 2;
  4616. }
  4617. else
  4618. {
  4619. tempIndex = gun_index;
  4620. }
  4621. for (int index = 0; index < AC_QUANTITY; index++)
  4622. {
  4623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4624. {
  4625. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4626. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4627. }
  4628. }
  4629. }
  4630. random_uuid(guid);
  4631. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4632. {
  4633. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4634. , gun_index +1
  4635. , MESSAGE_TYPE_CALL
  4636. , guid
  4637. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4638. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4639. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4640. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4641. }
  4642. else
  4643. {
  4644. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4645. , gun_index +1
  4646. , MESSAGE_TYPE_CALL
  4647. , guid
  4648. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4649. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4650. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4651. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4652. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4653. }
  4654. #if 1
  4655. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4656. 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*/)
  4657. {
  4658. result = PASS;
  4659. }
  4660. #endif
  4661. strcpy(queuedata, message);
  4662. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4663. OCPP_insert_transaction_msg(YES, queuedata);
  4664. return result;
  4665. }
  4666. int sendStatusNotificationRequest(int gun_index)
  4667. {
  4668. mtrace();
  4669. int result = FAIL;
  4670. char message[600]={0};
  4671. char guid[37];
  4672. int currentStatus = 0;
  4673. struct timeval tmnow;
  4674. struct tm *tm;
  4675. char buf[28];//, usec_buf[6];
  4676. char tempdata[65]={0};
  4677. int tempIndex = 0;
  4678. uint8_t isStateChanged = TRUE;
  4679. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4680. gettimeofday(&tmnow, NULL);
  4681. time_t t;
  4682. t = time(NULL);
  4683. /*UTC time and date*/
  4684. tm = gmtime(&t);
  4685. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4686. #if 0 // remove temporally
  4687. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4688. strcat(buf,".");
  4689. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4690. strcat(buf,usec_buf);
  4691. #endif
  4692. //printf("%s",buf);
  4693. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4694. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4695. // it's option
  4696. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4697. /*
  4698. enum _SYSTEM_STATUS
  4699. {
  4700. S_BOOTING = 0,
  4701. S_IDLE, = 1
  4702. S_AUTHORIZING, =2
  4703. S_REASSIGN_CHECK, =3
  4704. S_REASSIGN, =4
  4705. S_PRECHARGE, =5
  4706. S_PREPARING_FOR_EV, =6
  4707. S_PREPARING_FOR_EVSE, =7
  4708. S_CHARGING, =8
  4709. S_TERMINATING, =9
  4710. S_COMPLETE, =10
  4711. S_ALARM, =11
  4712. S_FAULT =12
  4713. }
  4714. */
  4715. //check Transaction active
  4716. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4717. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4718. {
  4719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4720. {
  4721. tempIndex = ((gun_index==2) ? 1: 0);
  4722. }
  4723. else
  4724. {
  4725. tempIndex = gun_index;
  4726. }
  4727. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4728. {
  4729. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4730. {
  4731. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4732. {
  4733. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4734. {
  4735. currentStatus = Preparing; //OCPP Status: Preparing
  4736. }
  4737. else
  4738. {
  4739. currentStatus = Available; //OCPP Status: Available
  4740. }
  4741. }
  4742. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4743. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4744. ) //S_PRECHARGE
  4745. {
  4746. currentStatus = Preparing; //OCPP Status: Preparing
  4747. }
  4748. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4749. {
  4750. currentStatus = Charging; //OCPP Status: Charging
  4751. }
  4752. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4753. {
  4754. currentStatus = Finishing; //OCPP Status: Finishing
  4755. }
  4756. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4757. {
  4758. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4759. }
  4760. 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
  4761. {
  4762. currentStatus = Unavailable; //OCPP Status: Unavailable
  4763. }
  4764. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4765. {
  4766. currentStatus = Faulted; //OCPP Status: Faulted
  4767. }
  4768. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4769. {
  4770. currentStatus = Reserved; //OCPP Status: Reserved
  4771. }
  4772. } //end of the same index
  4773. }//end of for CHAdeMO_QUANTITY
  4774. }
  4775. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4776. {
  4777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4778. {
  4779. tempIndex = ((gun_index==2) ? 1: 0);
  4780. }
  4781. else
  4782. {
  4783. tempIndex = gun_index;
  4784. }
  4785. for (int index = 0; index < CCS_QUANTITY; index++)
  4786. {
  4787. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4788. {
  4789. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4790. {
  4791. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4792. {
  4793. currentStatus = Preparing; //OCPP Status: Preparing
  4794. }
  4795. else
  4796. {
  4797. currentStatus = Available; //OCPP Status: Available
  4798. }
  4799. }
  4800. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4801. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4802. ) //S_PRECHARGE
  4803. {
  4804. currentStatus = Preparing; //OCPP Status: Preparing
  4805. }
  4806. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4807. {
  4808. currentStatus = Charging; //OCPP Status: Charging
  4809. }
  4810. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4811. {
  4812. currentStatus = Finishing; //OCPP Status: Finishing
  4813. }
  4814. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4815. {
  4816. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4817. }
  4818. 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
  4819. {
  4820. currentStatus = Unavailable; //OCPP Status : Unavailable
  4821. }
  4822. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4823. {
  4824. currentStatus = Faulted; //OCPP Status: Faulted
  4825. }
  4826. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4827. {
  4828. currentStatus = Reserved; //OCPP Status: Reserved
  4829. }
  4830. } //end of the same index
  4831. } // end of for CCS_QUANTITY
  4832. }
  4833. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4834. {
  4835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4836. {
  4837. tempIndex = ((gun_index==2) ? 1: 0);
  4838. }
  4839. else
  4840. {
  4841. tempIndex = gun_index;
  4842. }
  4843. for (int index = 0; index < GB_QUANTITY; index++)
  4844. {
  4845. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4846. {
  4847. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4848. {
  4849. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4850. {
  4851. currentStatus = Preparing; //OCPP Status: Preparing
  4852. }
  4853. else
  4854. {
  4855. currentStatus = Available; //OCPP Status: Available
  4856. }
  4857. }
  4858. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4859. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4860. ) //S_PRECHARGE
  4861. {
  4862. currentStatus = Preparing; //OCPP Status: Preparing
  4863. }
  4864. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4865. {
  4866. currentStatus = Charging; //OCPP Status: Charging
  4867. }
  4868. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4869. {
  4870. currentStatus = Finishing; //OCPP Status: Finishing
  4871. }
  4872. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4873. {
  4874. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4875. }
  4876. 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
  4877. {
  4878. currentStatus = Unavailable; //OCPP Status: Unavailable
  4879. }
  4880. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4881. {
  4882. currentStatus = Faulted; //OCPP Status: Faulted
  4883. }
  4884. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4885. {
  4886. currentStatus = Reserved; //OCPP Status: Reserved
  4887. }
  4888. } //end of the same index
  4889. } // end of for GB_QUANTITY
  4890. }
  4891. else if(gunType[gun_index] == GUN_TYPE_DO)
  4892. {
  4893. tempIndex = gun_index;
  4894. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4895. {
  4896. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4897. {
  4898. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4899. {
  4900. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4901. {
  4902. currentStatus = Preparing; //OCPP Status: Preparing
  4903. }
  4904. else
  4905. {
  4906. currentStatus = Available; //OCPP Status: Available
  4907. }
  4908. }
  4909. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4910. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4911. ) //S_PRECHARGE
  4912. {
  4913. currentStatus = Preparing; //OCPP Status: Preparing
  4914. }
  4915. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4916. {
  4917. currentStatus = Charging; //OCPP Status: Charging
  4918. }
  4919. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4920. {
  4921. currentStatus = Finishing; //OCPP Status: Finishing
  4922. }
  4923. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4924. {
  4925. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4926. }
  4927. 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
  4928. {
  4929. currentStatus = Unavailable; //OCPP Status: Unavailable
  4930. }
  4931. 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
  4932. {
  4933. currentStatus = Faulted; //OCPP Status: Faulted
  4934. }
  4935. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4936. {
  4937. currentStatus = Reserved; //OCPP Status: Reserved
  4938. }
  4939. } //end of the same index
  4940. }
  4941. }
  4942. else
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4945. {
  4946. tempIndex = 2;
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < AC_QUANTITY; index++)
  4953. {
  4954. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4955. {
  4956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4957. {
  4958. 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))
  4959. {
  4960. currentStatus = Preparing; //OCPP Status: Preparing
  4961. }
  4962. else
  4963. {
  4964. currentStatus = Available; //OCPP Status: Available
  4965. }
  4966. }
  4967. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4968. {
  4969. currentStatus = Preparing; //OCPP Status: Preparing
  4970. }
  4971. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4972. {
  4973. currentStatus = Charging; //OCPP Status: Charging
  4974. }
  4975. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4976. {
  4977. currentStatus = Finishing; //OCPP Status: Finishing
  4978. }
  4979. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4980. {
  4981. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4982. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4983. else
  4984. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4985. }
  4986. 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
  4987. {
  4988. currentStatus = Unavailable; //OCPP Status: Unavailable
  4989. }
  4990. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4991. {
  4992. currentStatus = Faulted; //OCPP Status: Faulted
  4993. }
  4994. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4995. {
  4996. currentStatus = Reserved; //OCPP Status: Reserved
  4997. }
  4998. }//end of the same index
  4999. }//end of for AC_QUANTITY
  5000. }
  5001. //it's option
  5002. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5003. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5004. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5005. {
  5006. isStateChanged = FALSE;
  5007. }
  5008. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5009. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5010. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5011. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5012. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5013. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5014. random_uuid(guid);
  5015. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5016. , MESSAGE_TYPE_CALL
  5017. , guid
  5018. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5019. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5020. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5021. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5022. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5023. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5024. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5025. if((server_sign == TRUE) && isStateChanged)
  5026. {
  5027. LWS_Send(message);
  5028. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5029. 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*/)
  5030. {
  5031. //DEBUG_ERROR("statusNotification mapitem pass");
  5032. result = PASS;
  5033. }
  5034. }
  5035. else
  5036. {
  5037. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5038. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5039. result = PASS;
  5040. }
  5041. return result;
  5042. }
  5043. int sendStopTransactionRequest(int gun_index)
  5044. {
  5045. mtrace();
  5046. int result = FAIL;
  5047. //char message[1500]={0};
  5048. char guid[37]={0};
  5049. char tempdata[65]={0};
  5050. int tempIndex = 0;
  5051. char TempStopTransaction[256];
  5052. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5053. //int idx_sample=0;
  5054. DEBUG_INFO("sendStopTransactionRequest \n");
  5055. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5056. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5057. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5058. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5059. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5060. {
  5061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5062. {
  5063. tempIndex = ((gun_index==2) ? 1: 0);
  5064. }
  5065. else
  5066. {
  5067. tempIndex = gun_index;
  5068. }
  5069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5070. {
  5071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5072. {
  5073. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5074. }
  5075. }// END OF CHAdeMO_QUANTITY
  5076. }
  5077. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5080. {
  5081. tempIndex = ((gun_index==2) ? 1: 0);
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < CCS_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5090. {
  5091. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5092. }
  5093. }// END OF CCS_QUANTITY
  5094. }
  5095. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5108. {
  5109. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5110. }
  5111. }// END OF GB_QUANTITY
  5112. }
  5113. else if(gunType[gun_index] == GUN_TYPE_DO)
  5114. {
  5115. tempIndex = gun_index;
  5116. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5117. {
  5118. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5119. {
  5120. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5121. }
  5122. }// END OF GB_QUANTITY
  5123. }
  5124. else
  5125. {
  5126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5127. {
  5128. tempIndex = 2;
  5129. }
  5130. else
  5131. {
  5132. tempIndex = gun_index;
  5133. }
  5134. for (int index = 0; index < AC_QUANTITY; index++)
  5135. {
  5136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5137. {
  5138. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5139. }
  5140. }// END OF AC_QUANTITY
  5141. }
  5142. //====================================== Stop Transaction Time =====================================================
  5143. struct timeval tmnow;
  5144. struct tm *tm;
  5145. char buf[28];//, usec_buf[6];
  5146. gettimeofday(&tmnow, NULL);
  5147. time_t t;
  5148. t = time(NULL);
  5149. /*UTC time and date*/
  5150. tm = gmtime(&t);
  5151. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5152. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5153. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5154. random_uuid(guid);
  5155. /***********************************transactionData******************************************************/
  5156. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5158. //=================================
  5159. // Transaction_Begin
  5160. //=================================
  5161. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5162. {
  5163. //============================================ Energy.Active.Import.Interval ================================
  5164. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5167. 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*/]);
  5168. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5169. 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))
  5170. {
  5171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5172. }
  5173. else
  5174. {
  5175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5176. }
  5177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5179. }
  5180. //=================================
  5181. // Transaction_End
  5182. //=================================
  5183. // ================================= Current.Import L1 ===============================================
  5184. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5185. {
  5186. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5187. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5188. {
  5189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5190. {
  5191. tempIndex = ((gun_index==2) ? 1: 0);
  5192. }
  5193. else
  5194. {
  5195. tempIndex = gun_index;
  5196. }
  5197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5198. {
  5199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5200. {
  5201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5202. }
  5203. }// End of for CHAdeMO_QUANTITY
  5204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5205. }
  5206. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5207. {
  5208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5209. {
  5210. tempIndex = ((gun_index==2) ? 1: 0);
  5211. }
  5212. else
  5213. {
  5214. tempIndex = gun_index;
  5215. }
  5216. for (int index = 0; index < CCS_QUANTITY; index++)
  5217. {
  5218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5219. {
  5220. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5221. }
  5222. }// End of for CCS_QUANTITY
  5223. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5224. }
  5225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5226. {
  5227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5228. {
  5229. tempIndex = ((gun_index==2) ? 1: 0);
  5230. }
  5231. else
  5232. {
  5233. tempIndex = gun_index;
  5234. }
  5235. for (int index = 0; index < GB_QUANTITY; index++)
  5236. {
  5237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5238. {
  5239. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5240. }
  5241. }// End of for GB_QUANTITY
  5242. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5243. }
  5244. else if(gunType[gun_index] == GUN_TYPE_DO)
  5245. {
  5246. tempIndex = gun_index;
  5247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5248. {
  5249. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5250. {
  5251. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5252. }
  5253. }
  5254. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5255. }
  5256. else
  5257. {
  5258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5259. {
  5260. tempIndex = 2;
  5261. }
  5262. else
  5263. {
  5264. tempIndex = gun_index;
  5265. }
  5266. for (int index = 0; index < AC_QUANTITY; index++)
  5267. {
  5268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5269. {
  5270. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5271. }
  5272. }// End of for AC_QUANTITY
  5273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5274. }
  5275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5280. }
  5281. // ================================= Energy.Active.Import.Interval ==============================================
  5282. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5283. {
  5284. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5285. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5286. {
  5287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5288. {
  5289. tempIndex = ((gun_index==2) ? 1: 0);
  5290. }
  5291. else
  5292. {
  5293. tempIndex = gun_index;
  5294. }
  5295. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5298. {
  5299. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5300. }
  5301. }// END OF CHAdeMO_QUANTITY
  5302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5303. }
  5304. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5305. {
  5306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5307. {
  5308. tempIndex = ((gun_index==2) ? 1: 0);
  5309. }
  5310. else
  5311. {
  5312. tempIndex = gun_index;
  5313. }
  5314. for (int index = 0; index < CCS_QUANTITY; index++)
  5315. {
  5316. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5317. {
  5318. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5319. }
  5320. }// END OF CCS_QUANTITY
  5321. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5322. }
  5323. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5324. {
  5325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5326. {
  5327. tempIndex = ((gun_index==2) ? 1: 0);
  5328. }
  5329. else
  5330. {
  5331. tempIndex = gun_index;
  5332. }
  5333. for (int index = 0; index < GB_QUANTITY; index++)
  5334. {
  5335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5336. {
  5337. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5338. }
  5339. }// END OF GB_QUANTITY
  5340. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5341. }
  5342. else if(gunType[gun_index] == GUN_TYPE_DO)
  5343. {
  5344. tempIndex = gun_index;
  5345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5346. {
  5347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5348. {
  5349. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5350. }
  5351. }
  5352. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5353. }
  5354. else
  5355. {
  5356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5357. {
  5358. tempIndex = 2;
  5359. }
  5360. else
  5361. {
  5362. tempIndex = gun_index;
  5363. }
  5364. for (int index = 0; index < AC_QUANTITY; index++)
  5365. {
  5366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5367. {
  5368. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5369. }
  5370. }// END OF AC_QUANTITY
  5371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5372. }
  5373. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5375. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5376. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5378. }
  5379. //=================================== Power.Active.Import ==================================================
  5380. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5381. {
  5382. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5383. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5384. {
  5385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5386. {
  5387. tempIndex = ((gun_index==2) ? 1: 0);
  5388. }
  5389. else
  5390. {
  5391. tempIndex = gun_index;
  5392. }
  5393. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5394. {
  5395. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5396. {
  5397. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5398. }
  5399. } // End for CHAdeMO_QUANTITY
  5400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5401. }
  5402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5403. {
  5404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5405. {
  5406. tempIndex = ((gun_index==2) ? 1: 0);
  5407. }
  5408. else
  5409. {
  5410. tempIndex = gun_index;
  5411. }
  5412. for (int index = 0; index < CCS_QUANTITY; index++)
  5413. {
  5414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5415. {
  5416. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5417. }
  5418. } // END for CCS_QUANTITY
  5419. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5420. }
  5421. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5422. {
  5423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5424. {
  5425. tempIndex = ((gun_index==2) ? 1: 0);
  5426. }
  5427. else
  5428. {
  5429. tempIndex = gun_index;
  5430. }
  5431. for (int index = 0; index < GB_QUANTITY; index++)
  5432. {
  5433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5434. {
  5435. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5436. }
  5437. }// END for GB_QUANTITY
  5438. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5439. }
  5440. else if(gunType[gun_index] == GUN_TYPE_DO)
  5441. {
  5442. tempIndex = gun_index;
  5443. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5444. {
  5445. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5446. {
  5447. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5448. }
  5449. }
  5450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5451. }
  5452. else
  5453. {
  5454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5455. {
  5456. tempIndex = 2;
  5457. }
  5458. else
  5459. {
  5460. tempIndex = gun_index;
  5461. }
  5462. for (int index = 0; index < AC_QUANTITY; index++)
  5463. {
  5464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5465. {
  5466. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5467. }
  5468. } // END for AC_QUANTITY
  5469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5470. }
  5471. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5472. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5474. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5476. }
  5477. //============================ Voltage L1 ====================================
  5478. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5479. {
  5480. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5481. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5482. {
  5483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5484. {
  5485. tempIndex = ((gun_index==2) ? 1: 0);
  5486. }
  5487. else
  5488. {
  5489. tempIndex = gun_index;
  5490. }
  5491. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5492. {
  5493. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5494. {
  5495. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5496. }
  5497. } // END OF FOR CHAdeMO_QUANTITY
  5498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5499. }
  5500. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5501. {
  5502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5503. {
  5504. tempIndex = ((gun_index==2) ? 1: 0);
  5505. }
  5506. else
  5507. {
  5508. tempIndex = gun_index;
  5509. }
  5510. for (int index = 0; index < CCS_QUANTITY; index++)
  5511. {
  5512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5513. {
  5514. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5515. }
  5516. } // END OF FOR CCS_QUANTITY
  5517. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5518. }
  5519. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5520. {
  5521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5522. {
  5523. tempIndex = ((gun_index==2) ? 1: 0);
  5524. }
  5525. else
  5526. {
  5527. tempIndex = gun_index;
  5528. }
  5529. for (int index = 0; index < GB_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5532. {
  5533. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5534. }
  5535. } // END OF FOR GB_QUANTITY
  5536. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5537. }
  5538. else if(gunType[gun_index] == GUN_TYPE_DO)
  5539. {
  5540. tempIndex = gun_index;
  5541. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5542. {
  5543. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5544. {
  5545. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5546. }
  5547. }
  5548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5549. }
  5550. else
  5551. {
  5552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5553. {
  5554. tempIndex = 2;
  5555. }
  5556. else
  5557. {
  5558. tempIndex = gun_index;
  5559. }
  5560. for (int index = 0; index < AC_QUANTITY; index++)
  5561. {
  5562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5563. {
  5564. 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
  5565. }
  5566. } // END OF FOR AC_QUANTITY
  5567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5568. }
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5574. }
  5575. //====================== End SoC ================================
  5576. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5577. {
  5578. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5579. 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))
  5580. {
  5581. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5582. {
  5583. tempIndex = ((gun_index==2) ? 1: 0);
  5584. }
  5585. else
  5586. {
  5587. tempIndex = gun_index;
  5588. }
  5589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5590. {
  5591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5592. {
  5593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5594. {
  5595. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5596. }
  5597. }
  5598. }
  5599. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5600. {
  5601. for (int index = 0; index < CCS_QUANTITY; index++)
  5602. {
  5603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5604. {
  5605. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5606. }
  5607. }
  5608. }
  5609. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5610. {
  5611. for (int index = 0; index < GB_QUANTITY; index++)
  5612. {
  5613. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5614. {
  5615. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5616. }
  5617. }
  5618. }
  5619. else if(gunType[gun_index] == GUN_TYPE_DO)
  5620. {
  5621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5622. {
  5623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5624. {
  5625. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5626. }
  5627. }
  5628. }
  5629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5633. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5635. } // END FOR DC CASE
  5636. }
  5637. // ================================= Current.Import L2 ===============================================
  5638. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5639. {
  5640. // AC 3 phse L2 current
  5641. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5642. {
  5643. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5644. {
  5645. tempIndex = 2;
  5646. }
  5647. else
  5648. {
  5649. tempIndex = gun_index;
  5650. }
  5651. for (int index = 0; index < AC_QUANTITY; index++)
  5652. {
  5653. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5654. {
  5655. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5656. }
  5657. }// End of for AC_QUANTITY
  5658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5659. }
  5660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5664. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5665. }
  5666. // ================================= Current.Import L3 ===============================================
  5667. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5668. {
  5669. // AC 3 phse L3 current
  5670. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5671. {
  5672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5673. {
  5674. tempIndex = 2;
  5675. }
  5676. else
  5677. {
  5678. tempIndex = gun_index;
  5679. }
  5680. for (int index = 0; index < AC_QUANTITY; index++)
  5681. {
  5682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5683. {
  5684. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5685. }
  5686. }// End of for AC_QUANTITY
  5687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5688. }
  5689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5690. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5691. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5692. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5693. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5694. }
  5695. //============================ Voltage L2 ====================================
  5696. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5697. {
  5698. // AC 3 phse L2 voltage
  5699. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5700. {
  5701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5702. {
  5703. tempIndex = 2;
  5704. }
  5705. else
  5706. {
  5707. tempIndex = gun_index;
  5708. }
  5709. for (int index = 0; index < AC_QUANTITY; index++)
  5710. {
  5711. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5712. {
  5713. 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
  5714. }
  5715. } // END OF FOR AC_QUANTITY
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5717. }
  5718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5719. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5721. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5722. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5723. }
  5724. //============================ Voltage L3 ====================================
  5725. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5726. {
  5727. // AC 3 phse L3 voltage
  5728. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5731. {
  5732. tempIndex = 2;
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < AC_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5741. {
  5742. 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
  5743. }
  5744. } // END OF FOR AC_QUANTITY
  5745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5746. }
  5747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5752. }
  5753. //====================== Start SoC ================================
  5754. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5755. {
  5756. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5757. 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))
  5758. {
  5759. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5760. {
  5761. tempIndex = ((gun_index==2) ? 1: 0);
  5762. }
  5763. else
  5764. {
  5765. tempIndex = gun_index;
  5766. }
  5767. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5768. {
  5769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5770. {
  5771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5772. {
  5773. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5774. }
  5775. }
  5776. }
  5777. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5778. {
  5779. for (int index = 0; index < CCS_QUANTITY; index++)
  5780. {
  5781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5782. {
  5783. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5784. }
  5785. }
  5786. }
  5787. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5788. {
  5789. for (int index = 0; index < GB_QUANTITY; index++)
  5790. {
  5791. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5792. {
  5793. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5794. }
  5795. }
  5796. }
  5797. else if(gunType[gun_index] == GUN_TYPE_DO)
  5798. {
  5799. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5800. {
  5801. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5802. {
  5803. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5804. }
  5805. }
  5806. }
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5810. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5813. } // END FOR DC CASE
  5814. }
  5815. //================================================ Message create ====================================================
  5816. json_object *StopTransaction = json_object_new_object();
  5817. json_object *transactionDatas = json_object_new_array();
  5818. json_object *sampledValues = json_object_new_array();
  5819. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5820. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5821. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5822. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5823. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5824. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5825. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5826. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5827. {
  5828. json_object *transactionData = json_object_new_object();
  5829. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5830. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5831. {
  5832. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5833. {
  5834. json_object *sampledValue = json_object_new_object();
  5835. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5836. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5837. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5838. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5839. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5840. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5841. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5842. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5843. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5844. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5845. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5846. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5847. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5848. json_object_array_add(sampledValues, sampledValue);
  5849. }
  5850. }
  5851. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5852. json_object_array_add(transactionDatas, transactionData);
  5853. }
  5854. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5855. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5856. ,MESSAGE_TYPE_CALL
  5857. ,guid
  5858. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5859. json_object_put(StopTransaction);
  5860. #if 1 // for TempStopTransaction
  5861. //Delete TempStopTransaction
  5862. if((access(TempStopTransaction,F_OK))!=-1)
  5863. {
  5864. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5865. }
  5866. #endif
  5867. #if 1
  5868. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5869. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5870. {
  5871. result = PASS;
  5872. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5873. }
  5874. #endif
  5875. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5876. OCPP_insert_transaction_msg(NO, queuedata);
  5877. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5878. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5879. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5880. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5881. {
  5882. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5883. }
  5884. //for test
  5885. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5886. return result;
  5887. }
  5888. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5889. {
  5890. mtrace();
  5891. int result = FAIL;
  5892. char guid[37]={0};
  5893. char tempdata[65]={0};
  5894. int tempIndex = 0;
  5895. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5896. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5897. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5898. //set value
  5899. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5900. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5901. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5902. -1);
  5903. random_uuid(guid);
  5904. //UTC Date time
  5905. struct timeval tmnow;
  5906. struct tm *tm;
  5907. char buf[28];//, usec_buf[6];
  5908. gettimeofday(&tmnow, NULL);
  5909. time_t t;
  5910. t = time(NULL);
  5911. /*UTC time and date*/
  5912. tm = gmtime(&t);
  5913. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5914. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5915. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5916. //********************************(1)Current.Import L1************************************************/
  5917. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5918. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5919. (dataType == ReadingContext_Trigger))
  5920. {
  5921. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5922. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5923. {
  5924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5925. {
  5926. tempIndex = ((gun_index==2) ? 1: 0);
  5927. }
  5928. else
  5929. {
  5930. tempIndex = gun_index;
  5931. }
  5932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5933. {
  5934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5935. {
  5936. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5937. }
  5938. }
  5939. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5940. }
  5941. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5942. {
  5943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5944. {
  5945. tempIndex = ((gun_index==2) ? 1: 0);
  5946. }
  5947. else
  5948. {
  5949. tempIndex = gun_index;
  5950. }
  5951. for (int index = 0; index < CCS_QUANTITY; index++)
  5952. {
  5953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5954. {
  5955. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5956. }
  5957. }
  5958. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5959. }
  5960. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5961. {
  5962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5963. {
  5964. tempIndex = ((gun_index==2) ? 1: 0);
  5965. }
  5966. else
  5967. {
  5968. tempIndex = gun_index;
  5969. }
  5970. for (int index = 0; index < GB_QUANTITY; index++)
  5971. {
  5972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5973. {
  5974. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5975. }
  5976. }
  5977. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5978. }
  5979. else if(gunType[gun_index] == GUN_TYPE_DO)
  5980. {
  5981. tempIndex = gun_index;
  5982. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5983. {
  5984. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5985. {
  5986. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5987. }
  5988. }
  5989. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5990. }
  5991. else
  5992. {
  5993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5994. {
  5995. tempIndex = 2;
  5996. }
  5997. else
  5998. {
  5999. tempIndex = gun_index;
  6000. }
  6001. for (int index = 0; index < AC_QUANTITY; index++)
  6002. {
  6003. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6004. {
  6005. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6006. }
  6007. }
  6008. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6009. }
  6010. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6011. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6012. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6014. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6015. }
  6016. //********************************(2)Energy.Active.Import.Register ************************************************/
  6017. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6018. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6019. (dataType == ReadingContext_Trigger))
  6020. {
  6021. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6022. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6023. {
  6024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6025. {
  6026. tempIndex = ((gun_index==2) ? 1: 0);
  6027. }
  6028. else
  6029. {
  6030. tempIndex = gun_index;
  6031. }
  6032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6033. {
  6034. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6035. {
  6036. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6037. }
  6038. }
  6039. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6040. }
  6041. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6042. {
  6043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6044. {
  6045. tempIndex = ((gun_index==2) ? 1: 0);
  6046. }
  6047. else
  6048. {
  6049. tempIndex = gun_index;
  6050. }
  6051. for (int index = 0; index < CCS_QUANTITY; index++)
  6052. {
  6053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6054. {
  6055. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6056. }
  6057. }
  6058. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6059. }
  6060. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6061. {
  6062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6063. {
  6064. tempIndex = ((gun_index==2) ? 1: 0);
  6065. }
  6066. else
  6067. {
  6068. tempIndex = gun_index;
  6069. }
  6070. for (int index = 0; index < GB_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6073. {
  6074. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6075. }
  6076. }
  6077. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6078. }
  6079. else if(gunType[gun_index] == GUN_TYPE_DO)
  6080. {
  6081. tempIndex = gun_index;
  6082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6083. {
  6084. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6085. {
  6086. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6087. }
  6088. }
  6089. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6090. }
  6091. else
  6092. {
  6093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6094. {
  6095. tempIndex = 2;
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. for (int index = 0; index < AC_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6106. }
  6107. }
  6108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6109. }
  6110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6111. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6114. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6115. }
  6116. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6117. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6118. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6119. (dataType == ReadingContext_Trigger))
  6120. {
  6121. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6122. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6123. {
  6124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6125. {
  6126. tempIndex = ((gun_index==2) ? 1: 0);
  6127. }
  6128. else
  6129. {
  6130. tempIndex = gun_index;
  6131. }
  6132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6133. {
  6134. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6135. {
  6136. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6137. }
  6138. } // END OF FOR CHAdeMO_QUANTITY
  6139. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6140. }
  6141. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6142. {
  6143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6144. {
  6145. tempIndex = ((gun_index==2) ? 1: 0);
  6146. }
  6147. else
  6148. {
  6149. tempIndex = gun_index;
  6150. }
  6151. for (int index = 0; index < CCS_QUANTITY; index++)
  6152. {
  6153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6154. {
  6155. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6156. }
  6157. } // END OF CCS_QUANTITY
  6158. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6159. }
  6160. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6161. {
  6162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6163. {
  6164. tempIndex = ((gun_index==2) ? 1: 0);
  6165. }
  6166. else
  6167. {
  6168. tempIndex = gun_index;
  6169. }
  6170. for (int index = 0; index < GB_QUANTITY; index++)
  6171. {
  6172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6173. {
  6174. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6175. }
  6176. } // END OF GB_QUANTITY
  6177. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6178. }
  6179. else if(gunType[gun_index] == GUN_TYPE_DO)
  6180. {
  6181. tempIndex = gun_index;
  6182. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6183. {
  6184. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6185. {
  6186. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6187. }
  6188. }
  6189. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6190. }
  6191. else
  6192. {
  6193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6194. {
  6195. tempIndex = 2;
  6196. }
  6197. else
  6198. {
  6199. tempIndex = gun_index;
  6200. }
  6201. for (int index = 0; index < AC_QUANTITY; index++)
  6202. {
  6203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6204. {
  6205. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6206. }
  6207. }
  6208. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6209. }
  6210. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6211. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6212. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6213. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6214. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6215. }
  6216. //********************************(4)Power.Active.Import************************************************/
  6217. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6218. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6219. (dataType == ReadingContext_Trigger))
  6220. {
  6221. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6222. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6223. {
  6224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6225. {
  6226. tempIndex = ((gun_index==2) ? 1: 0);
  6227. }
  6228. else
  6229. {
  6230. tempIndex = gun_index;
  6231. }
  6232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6233. {
  6234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6235. {
  6236. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6237. }
  6238. } // END OF FOR
  6239. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6240. }
  6241. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6242. {
  6243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6244. {
  6245. tempIndex = ((gun_index==2) ? 1: 0);
  6246. }
  6247. else
  6248. {
  6249. tempIndex = gun_index;
  6250. }
  6251. for (int index = 0; index < CCS_QUANTITY; index++)
  6252. {
  6253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6254. {
  6255. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6256. }
  6257. }
  6258. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6259. }
  6260. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6261. {
  6262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6263. {
  6264. tempIndex = ((gun_index==2) ? 1: 0);
  6265. }
  6266. else
  6267. {
  6268. tempIndex = gun_index;
  6269. }
  6270. for (int index = 0; index < GB_QUANTITY; index++)
  6271. {
  6272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6273. {
  6274. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6275. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6276. }
  6277. }
  6278. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6279. }
  6280. else if(gunType[gun_index] == GUN_TYPE_DO)
  6281. {
  6282. tempIndex = gun_index;
  6283. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6284. {
  6285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6286. {
  6287. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6288. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6289. }
  6290. }
  6291. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6292. }
  6293. else
  6294. {
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6296. {
  6297. tempIndex = 2;
  6298. }
  6299. else
  6300. {
  6301. tempIndex = gun_index;
  6302. }
  6303. for (int index = 0; index < AC_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6306. {
  6307. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6308. }
  6309. }
  6310. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6311. }
  6312. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6313. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6314. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6315. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6316. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6317. }
  6318. //***********************************************(5)VOLTAGE L1******************************************************/
  6319. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6320. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6321. (dataType == ReadingContext_Trigger))
  6322. {
  6323. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6324. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6325. {
  6326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6327. {
  6328. tempIndex = ((gun_index==2) ? 1: 0);
  6329. }
  6330. else
  6331. {
  6332. tempIndex = gun_index;
  6333. }
  6334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6335. {
  6336. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6337. {
  6338. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6339. }
  6340. }
  6341. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6342. }
  6343. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6344. {
  6345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6346. {
  6347. tempIndex = ((gun_index==2) ? 1: 0);
  6348. }
  6349. else
  6350. {
  6351. tempIndex = gun_index;
  6352. }
  6353. for (int index = 0; index < CCS_QUANTITY; index++)
  6354. {
  6355. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6356. {
  6357. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6358. }
  6359. }
  6360. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6361. }
  6362. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6363. {
  6364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6365. {
  6366. tempIndex = ((gun_index==2) ? 1: 0);
  6367. }
  6368. else
  6369. {
  6370. tempIndex = gun_index;
  6371. }
  6372. for (int index = 0; index < GB_QUANTITY; index++)
  6373. {
  6374. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6375. {
  6376. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6377. }
  6378. }
  6379. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6380. }
  6381. else if(gunType[gun_index] == GUN_TYPE_DO)
  6382. {
  6383. tempIndex = gun_index;
  6384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6385. {
  6386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6387. {
  6388. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6389. }
  6390. }
  6391. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6392. }
  6393. else
  6394. {
  6395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6396. {
  6397. tempIndex = 2;
  6398. }
  6399. else
  6400. {
  6401. tempIndex = gun_index;
  6402. }
  6403. for (int index = 0; index < AC_QUANTITY; index++)
  6404. {
  6405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6406. {
  6407. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6408. }
  6409. }
  6410. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6411. }
  6412. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6413. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6414. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6415. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6416. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6417. }
  6418. //***********************************************(6)SOC******************************************************/
  6419. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6420. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6421. (dataType == ReadingContext_Trigger))
  6422. {
  6423. 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))
  6424. {
  6425. //idx_sample=5;
  6426. //sampledValue = NULL;
  6427. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6428. {
  6429. tempIndex = ((gun_index==2) ? 1: 0);
  6430. }
  6431. else
  6432. {
  6433. tempIndex = gun_index;
  6434. }
  6435. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6436. {
  6437. //tempIndex = ((gun_index==2) ? 1: 0);
  6438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6441. {
  6442. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6443. }
  6444. }
  6445. }
  6446. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6447. {
  6448. //tempIndex = ((gun_index==2) ? 1: 0);
  6449. for (int index = 0; index < CCS_QUANTITY; index++)
  6450. {
  6451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6452. {
  6453. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6454. }
  6455. }
  6456. }
  6457. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6458. {
  6459. //tempIndex = ((gun_index==2) ? 1: 0);
  6460. for (int index = 0; index < GB_QUANTITY; index++)
  6461. {
  6462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6463. {
  6464. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6465. }
  6466. }
  6467. }
  6468. else if(gunType[gun_index] == GUN_TYPE_DO)
  6469. {
  6470. //tempIndex = ((gun_index==2) ? 1: 0);
  6471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6476. }
  6477. }
  6478. }
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6484. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6485. }
  6486. }
  6487. //********************************(7)Current.Import L2************************************************/
  6488. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6489. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6490. (dataType == ReadingContext_Trigger))
  6491. {
  6492. // Only for AC 3 phase
  6493. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6494. {
  6495. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6496. {
  6497. tempIndex = 2;
  6498. }
  6499. else
  6500. {
  6501. tempIndex = gun_index;
  6502. }
  6503. for (int index = 0; index < AC_QUANTITY; index++)
  6504. {
  6505. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6506. {
  6507. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6508. }
  6509. }
  6510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6511. }
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6517. }
  6518. //********************************(8)Current.Import L3************************************************/
  6519. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6520. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6521. (dataType == ReadingContext_Trigger))
  6522. {
  6523. // Only for AC 3 phase
  6524. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6525. {
  6526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6527. {
  6528. tempIndex = 2;
  6529. }
  6530. else
  6531. {
  6532. tempIndex = gun_index;
  6533. }
  6534. for (int index = 0; index < AC_QUANTITY; index++)
  6535. {
  6536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6537. {
  6538. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6539. }
  6540. }
  6541. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6542. }
  6543. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6544. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6545. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6546. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6548. }
  6549. //***********************************************(9)VOLTAGE L2******************************************************/
  6550. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6551. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6552. (dataType == ReadingContext_Trigger))
  6553. {
  6554. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6555. {
  6556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6557. {
  6558. tempIndex = 2;
  6559. }
  6560. else
  6561. {
  6562. tempIndex = gun_index;
  6563. }
  6564. for (int index = 0; index < AC_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6567. {
  6568. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6569. }
  6570. }
  6571. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6572. }
  6573. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6574. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6575. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6576. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6577. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6578. }
  6579. //***********************************************(10)VOLTAGE L3******************************************************/
  6580. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6581. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6582. (dataType == ReadingContext_Trigger))
  6583. {
  6584. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6585. {
  6586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6587. {
  6588. tempIndex = 2;
  6589. }
  6590. else
  6591. {
  6592. tempIndex = gun_index;
  6593. }
  6594. for (int index = 0; index < AC_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6597. {
  6598. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6599. }
  6600. }
  6601. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6602. }
  6603. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6604. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6605. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6606. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6607. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6608. }
  6609. //***********************************************(11)Current.Offered******************************************************/
  6610. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6611. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6612. (dataType == ReadingContext_Trigger))
  6613. {
  6614. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6615. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6616. {
  6617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6618. {
  6619. tempIndex = ((gun_index==2) ? 1: 0);
  6620. }
  6621. else
  6622. {
  6623. tempIndex = gun_index;
  6624. }
  6625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6626. {
  6627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6628. {
  6629. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6630. }
  6631. } // END OF FOR CHAdeMO_QUANTITY
  6632. }
  6633. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6634. {
  6635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6636. {
  6637. tempIndex = ((gun_index==2) ? 1: 0);
  6638. }
  6639. else
  6640. {
  6641. tempIndex = gun_index;
  6642. }
  6643. for (int index = 0; index < CCS_QUANTITY; index++)
  6644. {
  6645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6646. {
  6647. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6648. }
  6649. } // END OF CCS_QUANTITY
  6650. }
  6651. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6652. {
  6653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6654. {
  6655. tempIndex = ((gun_index==2) ? 1: 0);
  6656. }
  6657. else
  6658. {
  6659. tempIndex = gun_index;
  6660. }
  6661. for (int index = 0; index < GB_QUANTITY; index++)
  6662. {
  6663. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6664. {
  6665. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6666. }
  6667. } // END OF GB_QUANTITY
  6668. }
  6669. else if(gunType[gun_index] == GUN_TYPE_DO)
  6670. {
  6671. tempIndex = gun_index;
  6672. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6673. {
  6674. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6675. {
  6676. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6677. }
  6678. }
  6679. }
  6680. else
  6681. {
  6682. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6683. {
  6684. tempIndex = 2;
  6685. }
  6686. else
  6687. {
  6688. tempIndex = gun_index;
  6689. }
  6690. for (int index = 0; index < AC_QUANTITY; index++)
  6691. {
  6692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6693. {
  6694. uint16_t currentOffer;
  6695. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6696. {
  6697. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6698. }
  6699. else
  6700. {
  6701. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6702. }
  6703. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6704. }
  6705. }
  6706. }
  6707. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6708. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6709. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6710. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6711. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6712. }
  6713. //***********************************************(12)Power.Offered******************************************************/
  6714. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6715. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6716. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6717. {
  6718. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6719. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6720. {
  6721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6722. {
  6723. tempIndex = ((gun_index==2) ? 1: 0);
  6724. }
  6725. else
  6726. {
  6727. tempIndex = gun_index;
  6728. }
  6729. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6730. {
  6731. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6732. {
  6733. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6734. }
  6735. } // END OF FOR CHAdeMO_QUANTITY
  6736. }
  6737. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6738. {
  6739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6740. {
  6741. tempIndex = ((gun_index==2) ? 1: 0);
  6742. }
  6743. else
  6744. {
  6745. tempIndex = gun_index;
  6746. }
  6747. for (int index = 0; index < CCS_QUANTITY; index++)
  6748. {
  6749. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6750. {
  6751. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6752. }
  6753. } // END OF CCS_QUANTITY
  6754. }
  6755. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6756. {
  6757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6758. {
  6759. tempIndex = ((gun_index==2) ? 1: 0);
  6760. }
  6761. else
  6762. {
  6763. tempIndex = gun_index;
  6764. }
  6765. for (int index = 0; index < GB_QUANTITY; index++)
  6766. {
  6767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6768. {
  6769. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6770. }
  6771. } // END OF GB_QUANTITY
  6772. }
  6773. else if(gunType[gun_index] == GUN_TYPE_DO)
  6774. {
  6775. tempIndex = gun_index;
  6776. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6777. {
  6778. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6779. {
  6780. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6781. }
  6782. }
  6783. }
  6784. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6785. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6786. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6787. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6788. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6789. }
  6790. // Message create ====================================================================================================
  6791. if(TRUE)
  6792. {
  6793. json_object *MeterValueReq = json_object_new_object();
  6794. json_object *MeterValues = json_object_new_array();
  6795. json_object *sampledValues = json_object_new_array();
  6796. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6797. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6798. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6799. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6800. {
  6801. json_object *MeterValue = json_object_new_object();
  6802. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6803. {
  6804. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6805. {
  6806. json_object *sampledValue = json_object_new_object();
  6807. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6808. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6809. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6810. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6811. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6812. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6813. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6814. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6815. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6816. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6817. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6818. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6819. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6820. json_object_array_add(sampledValues, sampledValue);
  6821. }
  6822. }
  6823. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6824. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6825. json_object_array_add(MeterValues, MeterValue);
  6826. }
  6827. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6828. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6829. ,gun_index + 1
  6830. ,MESSAGE_TYPE_CALL
  6831. ,guid
  6832. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6833. json_object_put(MeterValueReq);
  6834. }
  6835. // Put request guid to hash map
  6836. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6837. 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*/)
  6838. {
  6839. result = PASS;
  6840. //DEBUG_INFO("MeterValues mapitem pass\n");
  6841. }
  6842. if((dataType != ReadingContext_Trigger) &&
  6843. (dataType != ReadingContext_Sample_Clock) &&
  6844. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6845. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6846. else
  6847. {
  6848. if(FirstHeartBeat)
  6849. LWS_Send(queuedata +2);
  6850. }
  6851. return result;
  6852. }
  6853. int sendLogStatusNotificationRequest(char *status)
  6854. {
  6855. mtrace();
  6856. int result = PASS;
  6857. char message[4096]={0};
  6858. char guid[37]={0};
  6859. char tempdata[128]={0};
  6860. json_object *LogStatusNotification = json_object_new_object();
  6861. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6862. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6863. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6864. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6865. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6866. random_uuid(guid);
  6867. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6868. json_object_put(LogStatusNotification);
  6869. LWS_Send(message);
  6870. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6871. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6872. {
  6873. result = PASS;
  6874. }
  6875. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6876. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6877. return result;
  6878. }
  6879. int sendSecurityEventNotificationRequest()
  6880. {
  6881. mtrace();
  6882. int result = PASS;
  6883. char message[4096]={0};
  6884. char guid[37]={0};
  6885. char tempdata[128]={0};
  6886. json_object *SecurityEventNotification = json_object_new_object();
  6887. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6888. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6889. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6890. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6891. random_uuid(guid);
  6892. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6893. json_object_put(SecurityEventNotification);
  6894. LWS_Send(message);
  6895. sprintf(tempdata, "SecurityEventNotification,0");
  6896. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6897. {
  6898. result = PASS;
  6899. }
  6900. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6901. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6902. return result;
  6903. }
  6904. int sendSignCertificateRequest()
  6905. {
  6906. mtrace();
  6907. int result = PASS;
  6908. char message[4096]={0};
  6909. char guid[37]={0};
  6910. char tempdata[128]={0};
  6911. json_object *SignCertificate = json_object_new_object();
  6912. DEBUG_INFO("sendSignCertificateRequest...\n");
  6913. // Read csr file content
  6914. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6915. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6916. char *line = NULL;
  6917. size_t len = 0;
  6918. while(getline(&line, &len, fp) != -1)
  6919. {
  6920. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6921. {
  6922. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6923. }
  6924. }
  6925. fclose(fp);
  6926. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6927. random_uuid(guid);
  6928. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6929. json_object_put(SignCertificate);
  6930. LWS_Send(message);
  6931. sprintf(tempdata, "SignCertificate,0");
  6932. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6933. {
  6934. result = PASS;
  6935. }
  6936. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6937. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6938. return result;
  6939. }
  6940. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6941. {
  6942. mtrace();
  6943. int result = PASS;
  6944. char message[110]={0};
  6945. char guid[37]={0};
  6946. char tempdata[65]={0};
  6947. json_object *FirmwareStatusNotification = json_object_new_object();
  6948. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6949. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6950. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6951. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6952. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6953. random_uuid(guid);
  6954. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6955. json_object_put(FirmwareStatusNotification);
  6956. LWS_Send(message);
  6957. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6958. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6959. {
  6960. result = PASS;
  6961. }
  6962. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6963. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6964. return result;
  6965. }
  6966. //==========================================
  6967. // send confirm routine
  6968. //==========================================
  6969. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6970. {
  6971. mtrace();
  6972. int result = FAIL;
  6973. char message[100]={0};
  6974. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6975. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6976. LWS_Send(message);
  6977. result = TRUE;
  6978. return result;
  6979. }
  6980. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6981. {
  6982. mtrace();
  6983. int result = FAIL;
  6984. char message[100]={0};
  6985. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6986. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6987. LWS_Send(message);
  6988. result = TRUE;
  6989. return result;
  6990. }
  6991. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6992. {
  6993. mtrace();
  6994. int result = FAIL;
  6995. char message[100]={0};
  6996. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6997. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6998. LWS_Send(message);
  6999. result = TRUE;
  7000. return result;
  7001. }
  7002. int sendClearCacheConfirmation(char *uuid,char *payload)
  7003. {
  7004. mtrace();
  7005. int result = FAIL;
  7006. char message[500]={0};
  7007. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7008. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7009. LWS_Send(message);
  7010. return result;
  7011. }
  7012. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7013. {
  7014. mtrace();
  7015. int result = FAIL;
  7016. char message[500]={0};
  7017. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7018. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7019. LWS_Send(message);
  7020. return result;
  7021. }
  7022. int sendDataTransferConfirmation(char *uuid,char *payload)
  7023. {
  7024. mtrace();
  7025. char statusStr[20]={0};
  7026. char dataStr[10]={0};
  7027. char sstr[20]={0};
  7028. int c = 0;
  7029. char *loc;
  7030. int result = FAIL;
  7031. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7032. /**********************status**************************/
  7033. loc = strstr(payload, "status");
  7034. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7035. c = 0;
  7036. while (loc[3+strlen("status")+c] != '\"')
  7037. {
  7038. sstr[c] = loc[3+strlen("status")+c];
  7039. c++;
  7040. }
  7041. sstr[c] = '\0';
  7042. strcpy(statusStr, sstr);
  7043. /**********************data**************************/
  7044. loc = strstr(payload, "data");
  7045. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7046. c = 0;
  7047. while (loc[3+strlen("data")+c] != '\"')
  7048. {
  7049. sstr[c] = loc[3+strlen("data")+c];
  7050. c++;
  7051. }
  7052. sstr[c] = '\0';
  7053. strcpy(dataStr, sstr);
  7054. return result;
  7055. }
  7056. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7057. {
  7058. mtrace();
  7059. int result = FAIL;
  7060. char message[1000]={0};
  7061. int CompositeScheduleIndex = 0;
  7062. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7063. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7064. if(nPeriod == 0)
  7065. {
  7066. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7067. {
  7068. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7069. ,MESSAGE_TYPE_CALLRESULT
  7070. ,uuid
  7071. ,payload
  7072. ,connectorIdInt);
  7073. }
  7074. else
  7075. {
  7076. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7077. ,MESSAGE_TYPE_CALLRESULT
  7078. ,uuid
  7079. ,payload
  7080. ,connectorIdInt
  7081. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7082. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7083. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7084. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7085. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7086. }
  7087. }
  7088. else
  7089. {
  7090. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7091. ,MESSAGE_TYPE_CALLRESULT
  7092. ,uuid
  7093. ,payload
  7094. ,connectorIdInt
  7095. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7096. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7097. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7098. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7099. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7100. {
  7101. if (idx_sample == 0)
  7102. {
  7103. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7104. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7105. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7106. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7107. }
  7108. else
  7109. {
  7110. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7111. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7112. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7113. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7114. }
  7115. }
  7116. sprintf(message + strlen(message), "]}}]");
  7117. }
  7118. LWS_Send(message);
  7119. result = TRUE;
  7120. return result;
  7121. }
  7122. int sendGetConfigurationConfirmation(char *uuid)
  7123. {
  7124. mtrace();
  7125. int result = FAIL;
  7126. int MaxKeySupported = 0;
  7127. int sentConfigurationNumber= 0;
  7128. int sentunConfigurationNumber= 0;
  7129. char message[1024*10]={0};
  7130. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7131. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7132. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7133. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7134. ,MESSAGE_TYPE_CALLRESULT
  7135. ,uuid );
  7136. //configuration key
  7137. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7138. {
  7139. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7140. {
  7141. if (sentConfigurationNumber == 0)
  7142. {
  7143. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7144. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7145. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7146. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7147. }
  7148. else
  7149. {
  7150. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7151. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7152. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7153. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7154. }
  7155. sentConfigurationNumber = sentConfigurationNumber + 1;
  7156. }
  7157. }
  7158. sprintf(message + strlen(message), "]");
  7159. if(UnknownKeynum != 0)
  7160. {
  7161. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7162. //unkown key
  7163. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7164. {
  7165. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7166. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7167. if(sentunConfigurationNumber == 0)
  7168. {
  7169. sprintf(message + strlen(message), "\"%s\""
  7170. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7171. }
  7172. else
  7173. {
  7174. sprintf(message + strlen(message), ",\"%s\""
  7175. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7176. }
  7177. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7178. }
  7179. sprintf(message + strlen(message), "]");
  7180. }
  7181. sprintf(message + strlen(message), "}]");
  7182. LWS_Send(message);
  7183. return result;
  7184. }
  7185. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7186. {
  7187. mtrace();
  7188. int result = FAIL;
  7189. char message[400]={0};
  7190. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7191. if(strcmp(payload,"")==0)
  7192. {
  7193. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7194. }
  7195. else
  7196. {
  7197. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7198. }
  7199. LWS_Send(message);
  7200. result = TRUE;
  7201. return result;
  7202. }
  7203. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7204. {
  7205. mtrace();
  7206. int result = FAIL;
  7207. char message[80]={0};
  7208. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7209. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7210. LWS_Send(message);
  7211. result = TRUE;
  7212. return result;
  7213. }
  7214. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7215. {
  7216. mtrace();
  7217. int result = FAIL;
  7218. char message[80]={0};
  7219. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7220. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7221. LWS_Send(message);
  7222. result = TRUE;
  7223. return result;
  7224. }
  7225. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7226. {
  7227. mtrace();
  7228. int result = FAIL;
  7229. char message[80]={0};
  7230. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7231. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7232. LWS_Send(message);
  7233. result = TRUE;
  7234. return result;
  7235. }
  7236. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7237. {
  7238. mtrace();
  7239. int result = FAIL;
  7240. char message[80]={0};
  7241. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7242. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7243. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7244. LWS_Send(message);
  7245. result = TRUE;
  7246. return result;
  7247. }
  7248. int sendResetConfirmation(char *uuid,char *payload)
  7249. {
  7250. mtrace();
  7251. int result = FAIL;
  7252. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7253. char message[80]={0};
  7254. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7255. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7256. LWS_Send(message);
  7257. result = TRUE;
  7258. return result;
  7259. }
  7260. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7261. {
  7262. mtrace();
  7263. int result = FAIL;
  7264. char message[500]={0};
  7265. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7266. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7267. LWS_Send(message);
  7268. result = TRUE;
  7269. return result;
  7270. }
  7271. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7272. {
  7273. mtrace();
  7274. int result = FAIL;
  7275. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7276. char message[80]={0};
  7277. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7278. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7279. LWS_Send(message);
  7280. result = TRUE;
  7281. return result;
  7282. }
  7283. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7284. {
  7285. mtrace();
  7286. int result = FAIL;
  7287. char message[80]={0};
  7288. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7289. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7290. LWS_Send(message);
  7291. result = TRUE;
  7292. return result;
  7293. }
  7294. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7295. {
  7296. mtrace();
  7297. int result = FAIL;
  7298. char message[80]={0};
  7299. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7300. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7301. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7302. LWS_Send(message);
  7303. result = TRUE;
  7304. return result;
  7305. }
  7306. int sendUpdateFirmwareConfirmation(char *uuid)
  7307. {
  7308. mtrace();
  7309. int result = FAIL;
  7310. char message[60]={0};
  7311. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7312. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7313. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7314. LWS_Send(message);
  7315. result = TRUE;
  7316. return result;
  7317. }
  7318. int sendCertificateSignedConfirmation(char *uuid)
  7319. {
  7320. mtrace();
  7321. int result = PASS;
  7322. char message[4096]={0};
  7323. json_object *CertificateSigned = json_object_new_object();
  7324. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7325. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7326. sprintf(message,"[%d,\"%s\",%s]"
  7327. ,MESSAGE_TYPE_CALLRESULT
  7328. ,uuid
  7329. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7330. json_object_put(CertificateSigned);
  7331. LWS_Send(message);
  7332. return result;
  7333. }
  7334. int sendDeleteCertificateConfirmation(char *uuid)
  7335. {
  7336. mtrace();
  7337. int result = PASS;
  7338. char message[4096]={0};
  7339. json_object *DeleteCertificate = json_object_new_object();
  7340. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7341. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7342. sprintf(message,"[%d,\"%s\",%s]"
  7343. ,MESSAGE_TYPE_CALLRESULT
  7344. ,uuid
  7345. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7346. json_object_put(DeleteCertificate);
  7347. LWS_Send(message);
  7348. return result;
  7349. }
  7350. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7351. {
  7352. mtrace();
  7353. int result = PASS;
  7354. char message[4096]={0};
  7355. json_object *ExtendedTriggerMessage = json_object_new_object();
  7356. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7357. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7358. sprintf(message,"[%d,\"%s\",%s]"
  7359. ,MESSAGE_TYPE_CALLRESULT
  7360. ,uuid
  7361. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7362. json_object_put(ExtendedTriggerMessage);
  7363. LWS_Send(message);
  7364. return result;
  7365. }
  7366. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7367. {
  7368. mtrace();
  7369. int result = PASS;
  7370. char message[4096]={0};
  7371. json_object *GetInstalledCertificateIds = json_object_new_object();
  7372. json_object *certificateHashDataDatas = json_object_new_array();
  7373. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7374. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7375. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7376. {
  7377. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7378. {
  7379. json_object *certificateHashData = json_object_new_object();
  7380. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7381. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7382. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7383. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7384. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7385. }
  7386. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7387. }
  7388. else
  7389. {
  7390. json_object_put(certificateHashDataDatas);
  7391. }
  7392. sprintf(message,"[%d,\"%s\",%s]"
  7393. ,MESSAGE_TYPE_CALLRESULT
  7394. ,uuid
  7395. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7396. json_object_put(GetInstalledCertificateIds);
  7397. LWS_Send(message);
  7398. return result;
  7399. }
  7400. int sendGetLogConfirmation(char *uuid)
  7401. {
  7402. mtrace();
  7403. int result = PASS;
  7404. char message[4096]={0};
  7405. json_object *GetLog = json_object_new_object();
  7406. DEBUG_INFO("sendGetLogConfirmation...\n");
  7407. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7408. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7409. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7410. sprintf(message,"[%d,\"%s\",%s]"
  7411. ,MESSAGE_TYPE_CALLRESULT
  7412. ,uuid
  7413. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7414. json_object_put(GetLog);
  7415. LWS_Send(message);
  7416. return result;
  7417. }
  7418. int sendInstallCertificateConfirmation(char *uuid)
  7419. {
  7420. mtrace();
  7421. int result = PASS;
  7422. char message[4096]={0};
  7423. json_object *InstallCertificate = json_object_new_object();
  7424. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7425. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7426. sprintf(message,"[%d,\"%s\",%s]"
  7427. ,MESSAGE_TYPE_CALLRESULT
  7428. ,uuid
  7429. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7430. json_object_put(InstallCertificate);
  7431. LWS_Send(message);
  7432. return result;
  7433. }
  7434. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7435. {
  7436. mtrace();
  7437. int result = PASS;
  7438. char message[4096]={0};
  7439. json_object *SignedUpdateFirmware = json_object_new_object();
  7440. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7441. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7442. sprintf(message,"[%d,\"%s\",%s]"
  7443. ,MESSAGE_TYPE_CALLRESULT
  7444. ,uuid
  7445. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7446. json_object_put(SignedUpdateFirmware);
  7447. LWS_Send(message);
  7448. return result;
  7449. }
  7450. int sendUnknownConfirmation(char *uuid)
  7451. {
  7452. mtrace();
  7453. int result = PASS;
  7454. char message[256]={0};
  7455. DEBUG_INFO("sendUnknownConfirmation...\n");
  7456. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7457. LWS_Send(message);
  7458. return result;
  7459. }
  7460. //==========================================
  7461. // Handle server request routine Start
  7462. //==========================================
  7463. int handleCancelReservationRequest(char *uuid, char *payload)
  7464. {
  7465. mtrace();
  7466. int result = FAIL;
  7467. int gunNO = 0;
  7468. int reservationIdInt = -1;
  7469. char comfirmstr[20];
  7470. DEBUG_INFO("handleCancelReservationRequest...\n");
  7471. json_object *CancelReservation;
  7472. CancelReservation = json_tokener_parse(payload);
  7473. if(!is_error(CancelReservation))
  7474. {
  7475. // Required data
  7476. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7477. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7478. }
  7479. json_object_put(CancelReservation);
  7480. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7481. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7482. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7483. if(reservationIdInt != -1)
  7484. {
  7485. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7486. //check Transaction active
  7487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7489. {
  7490. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7491. {
  7492. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7493. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7494. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7495. {
  7496. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7497. }
  7498. else
  7499. {
  7500. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7501. }
  7502. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7503. goto end;
  7504. }
  7505. }
  7506. for (int index = 0; index < CCS_QUANTITY; index++)
  7507. {
  7508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7509. {
  7510. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7511. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7512. if(gunType[2] == GUN_TYPE_CCS)
  7513. {
  7514. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7515. }
  7516. else
  7517. {
  7518. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7519. }
  7520. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7521. goto end;
  7522. }
  7523. }
  7524. for (int index = 0; index < GB_QUANTITY; index++)
  7525. {
  7526. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7527. {
  7528. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7529. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7530. if(gunType[2] == GUN_TYPE_GBT)
  7531. {
  7532. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7533. }
  7534. else
  7535. {
  7536. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7537. }
  7538. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7539. goto end;
  7540. }
  7541. }
  7542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7543. {
  7544. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7545. {
  7546. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7547. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7548. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7549. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7550. goto end;
  7551. }
  7552. }
  7553. for (int index = 0; index < AC_QUANTITY; index++)
  7554. {
  7555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7556. {
  7557. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7558. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7560. {
  7561. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7562. }
  7563. else
  7564. {
  7565. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7566. }
  7567. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7568. goto end;
  7569. }
  7570. }
  7571. }
  7572. //The reservationId does NOT match the reservationId
  7573. sendCancelReservationConfirmation(uuid, comfirmstr);
  7574. end:
  7575. // Fill in ocpp packet uuid
  7576. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7577. return result;
  7578. }
  7579. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7580. {
  7581. mtrace();
  7582. int result = FAIL;
  7583. int gunIndex = -1;
  7584. char typeStr[16]={0};
  7585. char comfirmstr[20];
  7586. int specificId = FALSE;
  7587. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7588. json_object *ChangeAvailability;
  7589. ChangeAvailability = json_tokener_parse(payload);
  7590. if(!is_error(ChangeAvailability))
  7591. {
  7592. // Required data
  7593. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7594. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7595. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7596. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7597. }
  7598. json_object_put(ChangeAvailability);
  7599. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7600. {
  7601. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7602. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7603. }
  7604. else if(gunIndex == 0)
  7605. {
  7606. for(int i=0; i < gunTotalNumber; i++)
  7607. {
  7608. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7609. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7610. }
  7611. }
  7612. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7614. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7615. {
  7616. specificId = TRUE;
  7617. }
  7618. if(specificId == FALSE)
  7619. goto end;
  7620. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7621. {
  7622. //----------------------gunIndex is 0 ------------------------------------------------//
  7623. if(gunIndex == 0)
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7626. {
  7627. for(int i=0; i < gunTotalNumber; i++)
  7628. {
  7629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7630. {
  7631. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7632. {
  7633. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7634. {
  7635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7636. goto end;
  7637. }
  7638. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7639. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7640. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7641. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7642. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7643. {
  7644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7645. goto end;
  7646. }
  7647. }
  7648. }//END FOR CHAdeMO_QUANTITY
  7649. for (int index = 0; index < CCS_QUANTITY; index++)
  7650. {
  7651. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7652. {
  7653. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7654. {
  7655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7656. goto end;
  7657. }
  7658. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7659. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7660. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7661. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7662. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7663. {
  7664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7665. goto end;
  7666. }
  7667. }
  7668. }//END FOR CCS_QUANTITY
  7669. for (int index = 0; index < GB_QUANTITY; index++)
  7670. {
  7671. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7672. {
  7673. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7674. {
  7675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7676. goto end;
  7677. }
  7678. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7679. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7680. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7681. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7682. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7683. {
  7684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7685. goto end;
  7686. }
  7687. }
  7688. }// END FOR GB_QUANTITY
  7689. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7690. {
  7691. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7692. {
  7693. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7694. {
  7695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7696. goto end;
  7697. }
  7698. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7699. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7700. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7701. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7702. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7703. {
  7704. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7705. goto end;
  7706. }
  7707. }
  7708. }// END FOR GENERAL_GUN_QUANTITY
  7709. for (int index = 0; index < AC_QUANTITY; index++)
  7710. {
  7711. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7712. {
  7713. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7714. {
  7715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7716. goto end;
  7717. }
  7718. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7719. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7720. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7721. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7722. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7723. {
  7724. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7725. goto end;
  7726. }
  7727. }
  7728. }//END FOR AC_QUANTITY
  7729. }// END FOR gunTotalNumber
  7730. }
  7731. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7732. {
  7733. for(int i=0; i < gunTotalNumber; i++)
  7734. {
  7735. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7736. {
  7737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7738. goto end;
  7739. }
  7740. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7741. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7742. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7743. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7744. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7745. {
  7746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7747. goto end;
  7748. }
  7749. }
  7750. }
  7751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7752. goto end;
  7753. }
  7754. //----------------------gunIndex is not 0 ------------------------------------------------//
  7755. //check Transaction active
  7756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7757. {
  7758. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7759. {
  7760. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7761. {
  7762. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7763. goto end;
  7764. }
  7765. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7766. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7767. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7768. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7769. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7770. {
  7771. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7772. goto end;
  7773. }
  7774. else
  7775. {
  7776. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7778. goto end;
  7779. }
  7780. }
  7781. }//END FOR CHAdeMO_QUANTITY
  7782. for (int index = 0; index < CCS_QUANTITY; index++)
  7783. {
  7784. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7785. {
  7786. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7787. {
  7788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7789. goto end;
  7790. }
  7791. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7792. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7793. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7794. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7795. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7796. {
  7797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7798. goto end;
  7799. }
  7800. else
  7801. {
  7802. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7803. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7804. goto end;
  7805. }
  7806. }
  7807. }//END FOR CCS_QUANTITY
  7808. for (int index = 0; index < GB_QUANTITY; index++)
  7809. {
  7810. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7811. {
  7812. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7813. {
  7814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7815. goto end;
  7816. }
  7817. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7818. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7819. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7820. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7821. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7822. {
  7823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7824. goto end;
  7825. }
  7826. else
  7827. {
  7828. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7829. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7830. goto end;
  7831. }
  7832. }
  7833. }// END FOR GB_QUANTITY
  7834. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7835. {
  7836. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7837. {
  7838. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7839. {
  7840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7841. goto end;
  7842. }
  7843. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7844. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7845. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7846. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7847. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7848. {
  7849. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7850. goto end;
  7851. }
  7852. else
  7853. {
  7854. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7855. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7856. goto end;
  7857. }
  7858. }
  7859. }// END FOR GENERAL_GUN_QUANTITY
  7860. for (int index = 0; index < AC_QUANTITY; index++)
  7861. {
  7862. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7863. {
  7864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7865. {
  7866. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7867. goto end;
  7868. }
  7869. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7870. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7871. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7872. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7873. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7874. {
  7875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7876. goto end;
  7877. }
  7878. else
  7879. {
  7880. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7881. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7882. goto end;
  7883. }
  7884. }
  7885. }//END FOR AC_QUANTITY
  7886. }//END FOR AvailabilityTypeStr[Inoperative]
  7887. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7888. {
  7889. //----------------------gunIndex is 0 ------------------------------------------------//
  7890. if(gunIndex == 0)
  7891. {
  7892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7893. {
  7894. for(int i=0; i < gunTotalNumber; i++)
  7895. {
  7896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7897. {
  7898. 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
  7899. {
  7900. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7901. goto end;
  7902. }
  7903. }//END FOR CHAdeMO_QUANTITY
  7904. for (int index = 0; index < CCS_QUANTITY; index++)
  7905. {
  7906. 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
  7907. {
  7908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7909. goto end;
  7910. }
  7911. }//END FOR CCS_QUANTITY
  7912. for (int index = 0; index < GB_QUANTITY; index++)
  7913. {
  7914. 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
  7915. {
  7916. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7917. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7918. goto end;
  7919. }
  7920. }// END FOR GB_QUANTITY
  7921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7922. {
  7923. 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
  7924. {
  7925. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7926. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7927. goto end;
  7928. }
  7929. }// END FOR GENERAL_GUN_QUANTITY
  7930. for (int index = 0; index < AC_QUANTITY; index++)
  7931. {
  7932. 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
  7933. {
  7934. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7935. goto end;
  7936. }
  7937. }//END FOR CHAdeMO_QUANTITY
  7938. }// END FOR gunTotalNumber
  7939. }
  7940. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7941. {
  7942. for(int i=0; i < gunTotalNumber; i++)
  7943. {
  7944. for (int index = 0; index < AC_QUANTITY; index++)
  7945. {
  7946. 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
  7947. {
  7948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7949. goto end;
  7950. }
  7951. }//END FOR CHAdeMO_QUANTITY
  7952. } // END FOR gunTotalNumber
  7953. }
  7954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7955. goto end;
  7956. }
  7957. //----------------------gunIndex is not 0 ------------------------------------------------//
  7958. //check Transaction active
  7959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7960. {
  7961. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7962. {
  7963. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7964. goto end;
  7965. }
  7966. }//END FOR CHAdeMO_QUANTITY
  7967. for (int index = 0; index < CCS_QUANTITY; index++)
  7968. {
  7969. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7970. {
  7971. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7972. goto end;
  7973. }
  7974. }//END FOR CCS_QUANTITY
  7975. for (int index = 0; index < GB_QUANTITY; index++)
  7976. {
  7977. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7978. {
  7979. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7980. goto end;
  7981. }
  7982. }// END FOR GB_QUANTITY
  7983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7984. {
  7985. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7986. {
  7987. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7988. goto end;
  7989. }
  7990. }// END FOR GENERAL_GUN_QUANTITY
  7991. for (int index = 0; index < AC_QUANTITY; index++)
  7992. {
  7993. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7994. {
  7995. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7996. goto end;
  7997. }
  7998. }//END FOR AC_QUANTITY
  7999. }//END FOR AvailabilityTypeStr[Operative]
  8000. end:
  8001. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8002. {
  8003. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8004. }
  8005. else
  8006. {
  8007. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8008. }
  8009. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8010. {
  8011. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8012. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8013. }
  8014. else if(gunIndex == 0)
  8015. {
  8016. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8017. {
  8018. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8019. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8020. }
  8021. }
  8022. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8023. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8024. return result;
  8025. }
  8026. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8027. {
  8028. mtrace();
  8029. int valueInvalid = NO;
  8030. int result = FAIL;
  8031. char keystr[40]={0};
  8032. char valuestr[501]={0}; //value should be limited in 500 bytes
  8033. char comfirmstr[20]={0};
  8034. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8035. json_object *ChangeConfiguration;
  8036. ChangeConfiguration = json_tokener_parse(payload);
  8037. if(!is_error(ChangeConfiguration))
  8038. {
  8039. // Required data
  8040. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8041. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8042. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8043. {
  8044. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8045. }
  8046. else
  8047. {
  8048. valueInvalid = YES;
  8049. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8050. }
  8051. }
  8052. json_object_put(ChangeConfiguration);
  8053. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8054. {
  8055. DEBUG_ERROR("Payload is null or not accepted.\n");
  8056. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8057. }
  8058. else
  8059. {
  8060. int status = setKeyValue(keystr, valuestr);
  8061. switch(status)
  8062. {
  8063. case ConfigurationStatus_Accepted:
  8064. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8065. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8066. StoreConfigurationTable();
  8067. break;
  8068. case RebootRequired:
  8069. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8070. StoreConfigurationTable();
  8071. break;
  8072. case NotSupported:
  8073. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8074. break;
  8075. case ConfigurationStatus_Rejected:
  8076. default:
  8077. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8078. break;
  8079. }
  8080. }
  8081. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8082. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8083. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8084. {
  8085. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8086. SetOcppConnStatus(FALSE);
  8087. }
  8088. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8089. {
  8090. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8091. }
  8092. return result;
  8093. }
  8094. int handleClearCacheRequest(char *uuid, char *payload)
  8095. {
  8096. mtrace();
  8097. int result = FAIL;
  8098. char comfirmstr[20];
  8099. char rmFileCmd[100]={0};
  8100. struct stat stats;
  8101. DEBUG_INFO("handleClearCacheRequest...\n");
  8102. stat("/Storage/OCPP_PH", &stats);
  8103. // Check for directory existence
  8104. if (S_ISDIR(stats.st_mode) == 1)
  8105. {}
  8106. else
  8107. {
  8108. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8109. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8110. system(rmFileCmd);
  8111. }
  8112. if(OCPP_cleanLocalCache())
  8113. {
  8114. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8115. }
  8116. else
  8117. {
  8118. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8119. }
  8120. sendClearCacheConfirmation(uuid, comfirmstr);
  8121. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8122. return result;
  8123. }
  8124. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8125. {
  8126. mtrace();
  8127. int result = FAIL;
  8128. int resultRename;
  8129. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8130. char chargingProfilePurposeStr[26]={0};
  8131. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8132. char tempchargingProfilePurposeStr[26]={0};
  8133. char str[100]={0};
  8134. char fname[200]={0};
  8135. char comfirmstr[20]={0};
  8136. char word[1600]={0};
  8137. int clearflag = FALSE;
  8138. int chargingProfileIdIsNULL = FALSE;
  8139. int connectorIsNULL = FALSE;
  8140. int chargingProfilePurposeIsNULL = FALSE;
  8141. int stackLevelIsNULL = FALSE;
  8142. //int GotoEnd = FALSE;
  8143. FILE *fptr1, *fptr2;
  8144. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8145. int n_chargingProfile=0;
  8146. int isEmptyFile = FALSE;
  8147. char sLineWord[1600]={0};
  8148. char chargingProfiles[10][100]={0};
  8149. int ChargeProfileCount = 0;
  8150. int ch;
  8151. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8152. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8153. json_object *ClearChargingProfile;
  8154. ClearChargingProfile = json_tokener_parse(payload);
  8155. if(!is_error(ClearChargingProfile))
  8156. {
  8157. // Optional data
  8158. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8159. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8160. else
  8161. chargingProfileIdIsNULL = TRUE;
  8162. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8163. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8164. else
  8165. connectorIsNULL = TRUE;
  8166. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8167. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8168. else
  8169. chargingProfilePurposeIsNULL = TRUE;
  8170. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8171. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8172. else
  8173. stackLevelIsNULL = TRUE;
  8174. }
  8175. json_object_put(ClearChargingProfile);
  8176. if(connectorIsNULL == FALSE)
  8177. {
  8178. switch(connectorIdInt)
  8179. {
  8180. case 0:
  8181. if(chargingProfilePurposeIsNULL == TRUE)
  8182. {
  8183. int l = 0;
  8184. strcpy(fname, ChargePointMaxProfile_JSON);
  8185. if((access(fname,F_OK))!=-1)
  8186. {
  8187. strcpy(chargingProfiles[l], fname);
  8188. l = l + 1;
  8189. }
  8190. strcpy(fname, TxDefaultProfile_0_JSON);
  8191. if((access(fname,F_OK))!=-1)
  8192. {
  8193. strcpy(chargingProfiles[l], fname);
  8194. l = l + 1;
  8195. }
  8196. ChargeProfileCount = l;
  8197. }
  8198. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8199. {
  8200. strcpy(fname, ChargePointMaxProfile_JSON);
  8201. if((access(fname,F_OK))!=-1)
  8202. {
  8203. strcpy(chargingProfiles[0], fname);
  8204. ChargeProfileCount = 1;
  8205. }
  8206. }
  8207. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8208. {
  8209. strcpy(fname, TxDefaultProfile_0_JSON);
  8210. if((access(fname,F_OK))!=-1)
  8211. {
  8212. strcpy(chargingProfiles[0], fname);
  8213. ChargeProfileCount = 1;
  8214. }
  8215. }
  8216. break;
  8217. default:
  8218. if(chargingProfilePurposeIsNULL == TRUE)
  8219. {
  8220. int m = 0;
  8221. memset(fname, 0, ARRAY_SIZE(fname));
  8222. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8223. if((access(fname,F_OK))!=-1)
  8224. {
  8225. strcpy(chargingProfiles[m], fname);
  8226. m = m + 1;
  8227. }
  8228. memset(fname, 0, ARRAY_SIZE(fname));
  8229. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8230. if((access(fname,F_OK))!=-1)
  8231. {
  8232. strcpy(chargingProfiles[m], fname);
  8233. m = m + 1;
  8234. }
  8235. ChargeProfileCount = m;
  8236. }
  8237. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8238. {
  8239. //strcpy(fname, TxDefaultProfile_1_JSON);
  8240. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8241. if((access(fname,F_OK))!=-1)
  8242. {
  8243. strcpy(chargingProfiles[0], fname);
  8244. ChargeProfileCount = 1;
  8245. }
  8246. }
  8247. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8248. {
  8249. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8250. if((access(fname,F_OK))!=-1)
  8251. {
  8252. strcpy(chargingProfiles[0], fname);
  8253. ChargeProfileCount = 1;
  8254. }
  8255. //strcpy(fname, TxProfile_1_JSON);
  8256. }
  8257. //strcpy(fname, ChargePointMaxProfile_JSON );
  8258. break;
  8259. }
  8260. }
  8261. else // Check all Charging Profiles
  8262. {
  8263. int i = 0;
  8264. char fnametemp[200]={0};
  8265. ChargeProfileCount = 0;
  8266. //Check ChargePointMaxProfile.json exit
  8267. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8268. {
  8269. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8270. i = i + 1;
  8271. }
  8272. //Check TxDefaultProfile_0.json exit
  8273. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8274. {
  8275. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8276. i = i + 1;
  8277. }
  8278. //Check TxDefaultProfile_%d.json
  8279. for(int j=1; j <= gunTotalNumber; j++)
  8280. {
  8281. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8282. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8283. if((access(fnametemp,F_OK))!=-1)
  8284. {
  8285. strcpy(chargingProfiles[i], fnametemp);
  8286. i = i + 1;
  8287. }
  8288. }
  8289. //Check TxProfile_%d.json
  8290. for(int j=1; j <= gunTotalNumber; j++)
  8291. {
  8292. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8293. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8294. if((access(fnametemp,F_OK))!=-1)
  8295. {
  8296. strcpy(chargingProfiles[i], fnametemp);
  8297. i = i + 1;
  8298. }
  8299. }
  8300. ChargeProfileCount = i;
  8301. }// End connectorIsNULL is TRUE
  8302. if(ChargeProfileCount == 0)
  8303. {
  8304. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8305. goto end;
  8306. }
  8307. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8308. {
  8309. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8310. goto end;
  8311. }
  8312. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8313. {
  8314. memset(str, 0, ARRAY_SIZE(str));
  8315. // clear temp file
  8316. sprintf(str,"rm -f %s",temp);
  8317. system(str);
  8318. for(int k=0; k < ChargeProfileCount; k++)
  8319. {
  8320. memset(str, 0, ARRAY_SIZE(str));
  8321. //clear file in C
  8322. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8323. system(str);
  8324. }
  8325. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8326. goto end;
  8327. }
  8328. else if(connectorIsNULL == TRUE)
  8329. {
  8330. for(int k=0; k < ChargeProfileCount; k++)
  8331. {
  8332. fptr1 = fopen(chargingProfiles[k], "r");
  8333. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8334. //Check Charging Profile Count
  8335. while(fscanf(fptr1, "%s", word) != EOF)
  8336. {
  8337. //DEBUG_INFO("word=%s\n",word);
  8338. if(strstr(word, "chargingProfileId")!= NULL)
  8339. {
  8340. //DEBUG_INFO("test chargingProfileId \n");
  8341. n_chargingProfile = n_chargingProfile + 1;
  8342. //DEBUG_INFO("chargingProfileId Found\n");
  8343. }
  8344. }
  8345. rewind(fptr1);
  8346. //search Charging Profile Element
  8347. //int i= 0;
  8348. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8349. {
  8350. json_object *tmpProfilee;
  8351. tmpProfilee = json_tokener_parse(sLineWord);
  8352. if(!is_error(tmpProfilee))
  8353. {
  8354. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8355. {
  8356. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8357. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8358. }
  8359. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8360. {
  8361. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8362. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8363. }
  8364. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8365. {
  8366. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8367. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8368. }
  8369. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8370. {
  8371. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8372. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8373. }
  8374. }
  8375. json_object_put(tmpProfilee);
  8376. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8377. {
  8378. //------- not write to fptr2-------//
  8379. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8380. //clearflag = TRUE;
  8381. }
  8382. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8383. {
  8384. //------- not write to fptr2-------//
  8385. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8386. }
  8387. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8388. {
  8389. //------- not write to fptr2-------//
  8390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8391. }
  8392. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8393. {
  8394. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8395. }
  8396. else
  8397. {
  8398. fprintf(fptr2, sLineWord);//writing data into file
  8399. }
  8400. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8401. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8402. if(clearflag == TRUE)
  8403. {
  8404. fclose(fptr1);
  8405. fclose(fptr2);
  8406. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8407. system(str);
  8408. // clear temp file
  8409. sprintf(str,"rm -f %s",temp);
  8410. system(str);
  8411. }
  8412. else
  8413. {
  8414. fclose(fptr1);
  8415. fclose(fptr2);
  8416. memset(str, 0, ARRAY_SIZE(str));
  8417. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8418. system(str);
  8419. resultRename = rename(temp, chargingProfiles[k]);
  8420. if(resultRename == 0)
  8421. {
  8422. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8423. }
  8424. else
  8425. {
  8426. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8427. }
  8428. if(comfirmstr[0]== 0)
  8429. {
  8430. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8431. }
  8432. //Check chargingProfile is empty file
  8433. /*------ Read the file ----------------*/
  8434. fptr1=fopen(chargingProfiles[k],"r");
  8435. ch=fgetc(fptr1);
  8436. rewind(fptr1);
  8437. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8438. if(ch!=EOF)
  8439. {
  8440. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8441. {
  8442. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8443. if(sLineWord[0]=='\0')
  8444. {
  8445. isEmptyFile = TRUE;
  8446. break;
  8447. }
  8448. else
  8449. {
  8450. isEmptyFile = FALSE;
  8451. break;
  8452. }
  8453. }
  8454. }
  8455. else
  8456. isEmptyFile = TRUE;
  8457. fclose(fptr1);
  8458. if(isEmptyFile == TRUE)
  8459. {
  8460. memset(str, 0, ARRAY_SIZE(str));
  8461. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8462. system(str);
  8463. }
  8464. }
  8465. }// End of while(int k=0; k < ChargePointCount; k++)
  8466. }
  8467. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8468. {
  8469. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8470. for(int k=0; k < ChargeProfileCount; k++)
  8471. {
  8472. fptr1 = fopen(chargingProfiles[k], "r");
  8473. fptr2 = fopen(temp, "w+");
  8474. //Check Charging Profile Count
  8475. while(fscanf(fptr1, "%s", word) != EOF)
  8476. {
  8477. //DEBUG_INFO("word=%s\n",word);
  8478. if(strstr(word, "chargingProfileId")!= NULL)
  8479. {
  8480. n_chargingProfile = n_chargingProfile + 1;
  8481. }
  8482. }
  8483. rewind(fptr1);
  8484. //search Charging Profile Element
  8485. //int i= 0;
  8486. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8487. {
  8488. json_object *tmpProfilee;
  8489. tmpProfilee = json_tokener_parse(sLineWord);
  8490. if(!is_error(tmpProfilee))
  8491. {
  8492. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8493. {
  8494. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8495. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8496. }
  8497. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8498. {
  8499. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8500. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8501. }
  8502. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8503. {
  8504. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8505. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8506. }
  8507. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8508. {
  8509. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8510. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8511. }
  8512. }
  8513. json_object_put(tmpProfilee);
  8514. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8515. {
  8516. //------- not write to fptr2-------//
  8517. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8518. //clearflag = TRUE;
  8519. }
  8520. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8521. {
  8522. //------- not write to fptr2-------//
  8523. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8524. }
  8525. else if(stackLevelIsNULL == TRUE)
  8526. {
  8527. //Clear Whole File
  8528. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8529. clearflag = TRUE;
  8530. break;
  8531. }
  8532. else
  8533. {
  8534. fprintf(fptr2, sLineWord);//writing data into file
  8535. }
  8536. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8537. }
  8538. if(clearflag == TRUE)
  8539. {
  8540. fclose(fptr1);
  8541. fclose(fptr2);
  8542. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8543. system(str);
  8544. // clear temp file
  8545. sprintf(str,"rm -f %s",temp);
  8546. system(str);
  8547. }
  8548. else
  8549. {
  8550. fclose(fptr1);
  8551. fclose(fptr2);
  8552. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8553. system(str);
  8554. resultRename = rename(temp, chargingProfiles[k]);
  8555. if(resultRename == 0)
  8556. {
  8557. DEBUG_INFO("File ChargingProfile renamed successfully");
  8558. }
  8559. else
  8560. {
  8561. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8562. }
  8563. if(comfirmstr[0]== 0)
  8564. {
  8565. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8566. }
  8567. //Check chargingProfile is empty file
  8568. /*------ Read the file ----------------*/
  8569. fptr1=fopen(chargingProfiles[k],"r");
  8570. ch=fgetc(fptr1);
  8571. rewind(fptr1);
  8572. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8573. if(ch!=EOF)
  8574. {
  8575. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8576. {
  8577. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8578. if(sLineWord[0]=='\0')
  8579. {
  8580. isEmptyFile = TRUE;
  8581. break;
  8582. }
  8583. else
  8584. {
  8585. isEmptyFile = FALSE;
  8586. break;
  8587. }
  8588. }
  8589. }
  8590. else
  8591. isEmptyFile = TRUE;
  8592. fclose(fptr1);
  8593. if(isEmptyFile == TRUE)
  8594. {
  8595. memset(str, 0, ARRAY_SIZE(str));
  8596. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8597. system(str);
  8598. }
  8599. /*------- End of reading ---------------*/
  8600. }
  8601. } // while(int k=0; k < ChargeProfileCount; k++)
  8602. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8603. end:
  8604. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8605. {
  8606. if(connectorIdInt == 0)
  8607. {
  8608. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8609. {
  8610. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8611. }
  8612. }
  8613. else
  8614. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8615. }
  8616. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8617. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8618. return result;
  8619. }
  8620. void createFirmwareVersionByDataTransfer(void)
  8621. {
  8622. json_object *FirmwareDataTransfer = json_object_new_object();
  8623. // AC & DC model
  8624. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8625. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8626. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8627. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8628. // DC model
  8629. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8630. {
  8631. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8632. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8633. (gunType[3] != GUN_TYPE_UNKNOWN))
  8634. {
  8635. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8636. }
  8637. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8638. {
  8639. // DS DM DW
  8640. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8641. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8642. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8643. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8644. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8645. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8646. }
  8647. else
  8648. {
  8649. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8650. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8651. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8652. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8653. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8654. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8655. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8656. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8657. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8658. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8659. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8660. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8661. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8663. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8665. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8667. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8669. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8670. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8671. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8672. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8673. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8674. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8675. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8676. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8677. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8678. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8679. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8680. }
  8681. }
  8682. // 4G model
  8683. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8684. {
  8685. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8686. }
  8687. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8688. json_object_put(FirmwareDataTransfer);
  8689. }
  8690. int handleDataTransferRequest(char *uuid, char *payload)
  8691. {
  8692. mtrace();
  8693. json_object *response = json_object_new_object();
  8694. int result = FAIL;
  8695. char tempvendorId[255]={0};
  8696. char tempmessageId[50]={0};
  8697. char tempdata[512]={0};
  8698. char message[2048]={0};
  8699. DEBUG_INFO("handleDataTransferRequest...\n");
  8700. if((uuid != NULL) && (payload != NULL))
  8701. {
  8702. json_object *DataTransfer;
  8703. DataTransfer = json_tokener_parse(payload);
  8704. if(!is_error(DataTransfer))
  8705. {
  8706. // Required data
  8707. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8708. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8709. // Optional data
  8710. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8711. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8712. if(json_object_object_get(DataTransfer, "data") != NULL)
  8713. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8714. result = PASS;
  8715. }
  8716. json_object_put(DataTransfer);
  8717. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8718. {
  8719. // Send all moudle firmware version on EVSE
  8720. createFirmwareVersionByDataTransfer();
  8721. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8722. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8723. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8724. json_object_put(response);
  8725. }
  8726. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8727. {
  8728. system("/usr/bin/run_tmate_restart.sh &");
  8729. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8730. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8731. json_object_put(response);
  8732. }
  8733. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8734. {
  8735. json_object *data;
  8736. data = json_tokener_parse(tempdata);
  8737. if(!is_error(data))
  8738. {
  8739. 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))
  8740. {
  8741. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8742. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8743. if(json_object_object_get(data, "SOC") != NULL)
  8744. {
  8745. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8746. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8747. }
  8748. if(json_object_object_get(data, "Energy") != NULL)
  8749. {
  8750. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8751. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8752. }
  8753. if(json_object_object_get(data, "Duration") != NULL)
  8754. {
  8755. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8756. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8757. }
  8758. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8759. }
  8760. else
  8761. {
  8762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8763. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8764. }
  8765. }
  8766. else
  8767. {
  8768. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8769. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8770. }
  8771. json_object_put(data);
  8772. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8773. json_object_put(response);
  8774. }
  8775. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8776. {
  8777. json_object *data;
  8778. data = json_tokener_parse(tempdata);
  8779. if(!is_error(data))
  8780. {
  8781. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8782. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8783. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8784. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8785. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8786. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8787. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8788. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8789. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8790. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8791. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8792. }
  8793. else
  8794. {
  8795. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8796. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8797. }
  8798. json_object_put(data);
  8799. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8800. json_object_put(response);
  8801. }
  8802. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8803. {
  8804. json_object *data;
  8805. data = json_tokener_parse(tempdata);
  8806. if(!is_error(data))
  8807. {
  8808. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8809. if(json_object_object_get(data, "idToken") != NULL)
  8810. {
  8811. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8812. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8813. }
  8814. if(json_object_object_get(data, "price") != NULL)
  8815. {
  8816. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8817. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8818. }
  8819. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8820. }
  8821. else
  8822. {
  8823. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8824. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8825. }
  8826. json_object_put(data);
  8827. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8828. json_object_put(response);
  8829. }
  8830. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8831. {
  8832. json_object *data;
  8833. data = json_tokener_parse(tempdata);
  8834. if(!is_error(data))
  8835. {
  8836. if(json_object_object_get(data, "txId") != NULL)
  8837. {
  8838. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8839. for(int idx = 0;idx<gunTotalNumber;idx++)
  8840. {
  8841. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8842. {
  8843. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8844. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8845. if(json_object_object_get(data, "description") != NULL)
  8846. {
  8847. // California pricing V1.0
  8848. DEBUG_INFO("California pricing V1.0\n");
  8849. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8850. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8851. }
  8852. else
  8853. {
  8854. // California pricing V1.1
  8855. DEBUG_INFO("California pricing V1.1\n");
  8856. if(json_object_object_get(data, "timestamp") != NULL)
  8857. {
  8858. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8859. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8860. }
  8861. if(json_object_object_get(data, "meterValue") != NULL)
  8862. {
  8863. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8864. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8865. }
  8866. if(json_object_object_get(data, "cost") != NULL)
  8867. {
  8868. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8869. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8870. }
  8871. if(json_object_object_get(data, "state") != NULL)
  8872. {
  8873. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8874. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8875. }
  8876. if(json_object_object_get(data, "chargingPrice") != NULL)
  8877. {
  8878. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8879. {
  8880. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8881. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8882. }
  8883. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8884. {
  8885. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8886. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8887. }
  8888. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8889. {
  8890. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8891. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8892. }
  8893. }
  8894. if(json_object_object_get(data, "idlePrice") != NULL)
  8895. {
  8896. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8897. {
  8898. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8899. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8900. }
  8901. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8902. {
  8903. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8904. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8905. }
  8906. }
  8907. if(json_object_object_get(data, "nextPeriod") != NULL)
  8908. {
  8909. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8910. {
  8911. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8912. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8913. }
  8914. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8915. {
  8916. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8917. {
  8918. 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")));
  8919. 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"));
  8920. }
  8921. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8922. {
  8923. 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")));
  8924. 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"));
  8925. }
  8926. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8927. {
  8928. 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")));
  8929. 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"));
  8930. }
  8931. }
  8932. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8933. {
  8934. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8935. {
  8936. 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")));
  8937. 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"));
  8938. }
  8939. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8940. {
  8941. 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")));
  8942. 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"));
  8943. }
  8944. }
  8945. }
  8946. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8947. {
  8948. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8949. {
  8950. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8951. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8952. }
  8953. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8954. {
  8955. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8956. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8957. }
  8958. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8959. {
  8960. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8961. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8962. }
  8963. }
  8964. }
  8965. }
  8966. }
  8967. }
  8968. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8969. }
  8970. else
  8971. {
  8972. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8973. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8974. }
  8975. json_object_put(data);
  8976. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8977. json_object_put(response);
  8978. }
  8979. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8980. {
  8981. json_object *data;
  8982. data = json_tokener_parse(tempdata);
  8983. if(!is_error(data))
  8984. {
  8985. if(json_object_object_get(data, "txId") != NULL)
  8986. {
  8987. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8988. for(int idx = 0;idx<gunTotalNumber;idx++)
  8989. {
  8990. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8991. {
  8992. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8993. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8994. if(json_object_object_get(data, "description") != NULL)
  8995. {
  8996. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8997. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8998. }
  8999. }
  9000. }
  9001. }
  9002. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9003. }
  9004. else
  9005. {
  9006. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9007. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9008. }
  9009. json_object_put(data);
  9010. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9011. json_object_put(response);
  9012. }
  9013. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9014. {
  9015. json_object *data;
  9016. data = json_tokener_parse(tempdata);
  9017. if(!is_error(data))
  9018. {
  9019. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9020. if(json_object_object_get(data, "Content_Type") != NULL)
  9021. {
  9022. 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))
  9023. {
  9024. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9025. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9026. {
  9027. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9028. }
  9029. }
  9030. else
  9031. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9032. }
  9033. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9034. }
  9035. else
  9036. {
  9037. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9038. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9039. }
  9040. json_object_put(data);
  9041. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9042. json_object_put(response);
  9043. }
  9044. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9045. {
  9046. json_object *data;
  9047. data = json_tokener_parse(tempdata);
  9048. if(!is_error(data))
  9049. {
  9050. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9051. if(json_object_object_get(data, "ConnectorId") != NULL)
  9052. {
  9053. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9054. }
  9055. if(json_object_object_get(data, "SerialNo") != NULL)
  9056. {
  9057. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.LineStatusPage.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9058. }
  9059. if(json_object_object_get(data, "Page_Index") != NULL)
  9060. {
  9061. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9062. }
  9063. if(json_object_object_get(data, "Duration") != NULL)
  9064. {
  9065. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9066. }
  9067. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9068. }
  9069. else
  9070. {
  9071. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9072. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9073. }
  9074. json_object_put(data);
  9075. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9076. json_object_put(response);
  9077. }
  9078. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9079. {
  9080. json_object *data;
  9081. data = json_tokener_parse(tempdata);
  9082. if(!is_error(data))
  9083. {
  9084. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9085. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9086. {
  9087. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9088. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9089. else
  9090. {
  9091. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9092. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9093. }
  9094. }
  9095. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9096. {
  9097. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9098. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9099. else
  9100. {
  9101. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9102. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9103. }
  9104. }
  9105. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9106. {
  9107. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9108. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9109. else
  9110. {
  9111. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9112. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9113. }
  9114. }
  9115. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9116. {
  9117. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9118. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9119. else
  9120. {
  9121. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9122. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9123. }
  9124. }
  9125. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9126. {
  9127. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9128. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9129. else
  9130. {
  9131. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9132. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9133. }
  9134. }
  9135. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9136. {
  9137. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9138. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9139. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9140. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9141. else
  9142. {
  9143. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9144. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9145. }
  9146. }
  9147. if(json_object_object_get(data, "isAuthentication") != NULL)
  9148. {
  9149. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9150. {
  9151. case 0:
  9152. case 1:
  9153. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9154. break;
  9155. default:
  9156. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9157. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9158. break;
  9159. }
  9160. }
  9161. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9162. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9163. }
  9164. else
  9165. {
  9166. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9167. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9168. }
  9169. json_object_put(data);
  9170. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9171. json_object_put(response);
  9172. }
  9173. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9174. {
  9175. json_object *data;
  9176. data = json_tokener_parse(tempdata);
  9177. if(!is_error(data))
  9178. {
  9179. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9180. if(json_object_object_get(data, "stationName") != NULL)
  9181. {
  9182. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9183. }
  9184. else
  9185. {
  9186. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9187. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9188. }
  9189. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9190. {
  9191. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9192. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9193. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9194. }
  9195. }
  9196. else
  9197. {
  9198. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9199. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9200. }
  9201. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9202. json_object_put(response);
  9203. }
  9204. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9205. {
  9206. json_object *data;
  9207. data = json_tokener_parse(tempdata);
  9208. if(!is_error(data))
  9209. {
  9210. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9211. if(json_object_object_get(data, "weatherId") != NULL)
  9212. {
  9213. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9214. }
  9215. else
  9216. {
  9217. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9218. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9219. }
  9220. if(json_object_object_get(data, "Temperature") != NULL)
  9221. {
  9222. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9223. }
  9224. else
  9225. {
  9226. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9227. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9228. }
  9229. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9230. {
  9231. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9232. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9233. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9234. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9235. }
  9236. }
  9237. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9238. {
  9239. json_object *data;
  9240. data = json_tokener_parse(tempdata);
  9241. if(!is_error(data))
  9242. {
  9243. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9244. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9245. {
  9246. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9247. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9248. }
  9249. else
  9250. {
  9251. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9252. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9253. }
  9254. }
  9255. else
  9256. {
  9257. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9258. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9259. }
  9260. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9261. json_object_put(response);
  9262. }
  9263. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9264. {
  9265. json_object *data;
  9266. data = json_tokener_parse(tempdata);
  9267. if(!is_error(data))
  9268. {
  9269. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9270. {
  9271. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9272. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9273. if(gun_index < gunTotalNumber)
  9274. {
  9275. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9276. {
  9277. json_object *responsedata = json_object_new_object();
  9278. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9279. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9280. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.LineStatusPage.SerialNo[gun_index]));
  9281. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9282. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9283. }
  9284. else
  9285. {
  9286. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9287. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9288. }
  9289. }
  9290. else
  9291. {
  9292. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9293. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9294. }
  9295. }
  9296. else
  9297. {
  9298. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9299. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9300. }
  9301. }
  9302. else
  9303. {
  9304. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9305. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9306. }
  9307. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9308. json_object_put(response);
  9309. }
  9310. else
  9311. {
  9312. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9313. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9314. }
  9315. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9316. json_object_put(response);
  9317. }
  9318. else
  9319. {
  9320. // Can not find valid message id
  9321. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9322. }
  9323. }
  9324. else
  9325. {
  9326. // Payload is null
  9327. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9328. }
  9329. LWS_Send(message);
  9330. return result;
  9331. }
  9332. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9333. {
  9334. mtrace();
  9335. int result = FAIL;
  9336. int connectorIdInt, durationInt;
  9337. char chargingRateUnitStr[4]={0};
  9338. char comfirmstr[20];
  9339. int confirmPeriods = 0;
  9340. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9341. json_object *GetCompositeSchedule;
  9342. GetCompositeSchedule = json_tokener_parse(payload);
  9343. if(!is_error(GetCompositeSchedule))
  9344. {
  9345. // Required data
  9346. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9347. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9348. else
  9349. connectorIdInt = -1;
  9350. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9351. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9352. else
  9353. durationInt = 86400;
  9354. // Optional data
  9355. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9356. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9357. }
  9358. json_object_put(GetCompositeSchedule);
  9359. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9360. if((connectorIdInt == 0) ||
  9361. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9362. {
  9363. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9364. struct StructChargingProfile tmpProfile[1];
  9365. if(strstr(chargingRateUnitStr, "W") != NULL)
  9366. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9367. else
  9368. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9369. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9370. {
  9371. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9372. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9373. }
  9374. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9375. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9376. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9377. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9378. {
  9379. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9380. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9381. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9382. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9383. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9384. {
  9385. confirmPeriods = idx;
  9386. break;
  9387. }
  9388. }
  9389. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9390. {
  9391. confirmPeriods += 1;
  9392. }
  9393. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9394. }
  9395. else
  9396. {
  9397. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9398. }
  9399. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9400. return result;
  9401. }
  9402. int handleGetConfigurationRequest(char *uuid, char *payload)
  9403. {
  9404. mtrace();
  9405. int result = FAIL;
  9406. int MaxKeySupported = 0;
  9407. int n_keys = 0;
  9408. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9409. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9410. json_object *GetConfiguration;
  9411. GetConfiguration = json_tokener_parse(payload);
  9412. if(!is_error(GetConfiguration))
  9413. {
  9414. // Optional data
  9415. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9416. {
  9417. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9418. {
  9419. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9420. n_keys = idx + 1;
  9421. }
  9422. }
  9423. }
  9424. json_object_put(GetConfiguration);
  9425. UnknownKeynum = 0;
  9426. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9427. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9428. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9429. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9430. if(n_keys != 0)
  9431. {
  9432. for(int i=0;i<n_keys;i++)
  9433. {
  9434. getKeyValue(requestKey[i]);
  9435. }
  9436. }
  9437. else
  9438. {
  9439. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9440. getKeyValue("");
  9441. }
  9442. processUnkownKey();
  9443. sendGetConfigurationConfirmation(uuid);
  9444. return result;
  9445. }
  9446. static char fnamePlusPath[100]={0};
  9447. static char fnamePWithNoPath[60]={0};
  9448. void checkUploadLog(void)
  9449. {
  9450. FILE *fp;
  9451. /* Open the command for reading. */
  9452. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9453. if (fp == NULL) {
  9454. DEBUG_WARN("Failed to run command\n" );
  9455. exit(1);
  9456. }
  9457. int ftppathlen = 0;
  9458. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9459. int i = 0;
  9460. /* Read the output a line at a time - output it. */
  9461. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9462. if(i==0)
  9463. {
  9464. ftppathlen = strlen(fnamePlusPath);
  9465. DEBUG_INFO("%s\n", fnamePlusPath);
  9466. fnamePlusPath[ftppathlen]='\0';
  9467. break;
  9468. }
  9469. i= i+1;
  9470. }
  9471. /* close */
  9472. pclose(fp);
  9473. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9474. {
  9475. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9476. {
  9477. fnamePlusPath[k]='\0';
  9478. }
  9479. }
  9480. i=1;
  9481. //char fname[60]={0};
  9482. while(i < ftppathlen)
  9483. {
  9484. int len=ftppathlen-i;
  9485. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9486. {
  9487. DEBUG_INFO("compare '/' all right\n");
  9488. break;
  9489. }
  9490. i=i+1;
  9491. }
  9492. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9493. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9494. fnamePWithNoPath[i+1] = '\0';
  9495. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9496. {
  9497. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9498. {
  9499. fnamePWithNoPath[j]='\0';
  9500. }
  9501. }
  9502. FILE* fp1 = fopen(fnamePlusPath, "r");
  9503. if (fp1)
  9504. {
  9505. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9506. // file exists
  9507. fclose(fp1);
  9508. }
  9509. else
  9510. {
  9511. // file doesn't exist
  9512. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9513. }
  9514. }
  9515. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9516. {
  9517. mtrace();
  9518. int result = FAIL;
  9519. time_t CurrentTime;
  9520. struct tm *tm;
  9521. pthread_t th_Status;
  9522. CurrentTime = time(NULL);
  9523. tm = localtime(&CurrentTime);
  9524. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9525. 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);
  9526. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9527. if(!interLock.isGetDiagnosticGoing)
  9528. {
  9529. interLock.isGetDiagnosticGoing = 1;
  9530. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9531. sleep(1);
  9532. }
  9533. else
  9534. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9535. return result;
  9536. }
  9537. void* GetDiagnosticsProcess(void* data)
  9538. {
  9539. pthread_detach(pthread_self());
  9540. mtrace();
  9541. int retriesInt=0, retryIntervalInt=0;
  9542. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9543. 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};
  9544. int port=0;
  9545. int isSuccess = FALSE;
  9546. char ftpbuf[200]={0};
  9547. char cmdBuf[2048];
  9548. struct tm *tmNow;
  9549. time_t CurrentTime;
  9550. struct tm tmStart;
  9551. struct tm tmStop;
  9552. CurrentTime = time(NULL);
  9553. tmNow=localtime(&CurrentTime);
  9554. uint16_t targetYear, targetMonth;
  9555. json_object *GetDiagnostics;
  9556. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9557. GetDiagnostics = json_tokener_parse(data);
  9558. if(!is_error(GetDiagnostics))
  9559. {
  9560. // Required data
  9561. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9562. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9563. // Optional data
  9564. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9565. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9566. else
  9567. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9568. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9569. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9570. else
  9571. retryIntervalInt = 30;
  9572. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9573. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9574. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9575. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9576. }
  9577. json_object_put(GetDiagnostics);
  9578. // Pack log to compress file
  9579. 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) &&
  9580. (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))
  9581. {
  9582. // Pack system log
  9583. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9584. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9585. targetYear = tmStart.tm_year;
  9586. targetMonth = tmStart.tm_mon;
  9587. do
  9588. {
  9589. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9590. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9591. if(targetMonth+1>=13)
  9592. {
  9593. targetYear += 1;
  9594. targetMonth = 1;
  9595. }
  9596. else
  9597. {
  9598. targetMonth += 1;
  9599. }
  9600. }while((targetYear < (tmNow->tm_year+1900)) ||
  9601. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9602. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9603. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9604. system(cmdBuf);
  9605. // Pack charging & event log
  9606. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9607. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9608. targetYear = tmStart.tm_year;
  9609. targetMonth = tmStart.tm_mon;
  9610. do
  9611. {
  9612. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9613. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9614. if(targetMonth+1>=13)
  9615. {
  9616. targetYear += 1;
  9617. targetMonth = 1;
  9618. }
  9619. else
  9620. {
  9621. targetMonth += 1;
  9622. }
  9623. }while((targetYear < (tmNow->tm_year+1900)) ||
  9624. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9625. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9626. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9627. system(cmdBuf);
  9628. // Combine log file
  9629. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9630. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9631. }
  9632. else
  9633. {
  9634. system("exec /root/logPackTools 'log' 6");
  9635. }
  9636. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9637. system(cmdBuf);
  9638. checkUploadLog();
  9639. //****************location*******************/
  9640. if(strcmp(locationstr,"")==0)
  9641. {
  9642. DEBUG_INFO("location is <Empty>!\n");
  9643. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9644. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9645. goto end;
  9646. }
  9647. memset(protocol, 0, ARRAY_SIZE(protocol));
  9648. memset(user, 0, ARRAY_SIZE(user) );
  9649. memset(password, 0, ARRAY_SIZE(password));
  9650. memset(host, 0, ARRAY_SIZE(host));
  9651. memset(path, 0, ARRAY_SIZE(path));
  9652. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9653. memset(host1, 0, ARRAY_SIZE(host1));
  9654. memset(path1, 0, ARRAY_SIZE(path1));
  9655. /*location: ftp://user:password@host:port/path*/
  9656. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9657. if((access(fnamePlusPath,F_OK))!=-1)
  9658. {
  9659. DEBUG_INFO("fnamePlusPath exist.\n");
  9660. }
  9661. else
  9662. {
  9663. DEBUG_INFO("fnamePlusPath not exist!\n");
  9664. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9665. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9666. goto end;
  9667. }
  9668. if(strchr(locationstr,'@')==NULL)
  9669. {
  9670. sscanf(locationstr,
  9671. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9672. protocol, host, &port, path);
  9673. strcpy(user,"anonymous");
  9674. strcpy(password,"");
  9675. }
  9676. else
  9677. {
  9678. //DEBUG_INFO("pch=%s\n", pch);
  9679. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9680. protocol, user, password, host, &port, path);
  9681. }
  9682. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9683. {
  9684. DEBUG_INFO("protocol is not ftp/http ! \n");
  9685. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9686. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9687. goto end;
  9688. }
  9689. if(strncmp(locationstr,"http", 4) == 0)
  9690. {
  9691. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9692. sprintf(ftppath,"/%s", path);
  9693. do
  9694. {
  9695. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9696. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9697. sleep(3);
  9698. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9699. if(!isSuccess)
  9700. {
  9701. DEBUG_INFO("Diagnostics fail.\n");
  9702. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9703. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9704. sleep(retryIntervalInt);
  9705. }
  9706. else
  9707. {
  9708. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9709. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9710. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9711. }
  9712. retriesInt--;
  9713. }while((isSuccess == 0)&&(retriesInt >= 0));
  9714. }
  9715. else
  9716. {
  9717. sscanf(host,"%[^/]%s",host1, path1);
  9718. if(strlen(path) > 0)
  9719. sprintf(ftppath,"/%s", path);
  9720. else
  9721. sprintf(ftppath,"/%s", path1);
  9722. int ftppathlen=strlen(ftppath);
  9723. int i=1;
  9724. char filenametemp[50];
  9725. while(i < ftppathlen)
  9726. {
  9727. int len=ftppathlen-i;
  9728. if(ftppath[len]== 47) // '/' ascll code: 47
  9729. {
  9730. DEBUG_INFO("find '/' all right\n");
  9731. break;
  9732. }
  9733. i=i+1;
  9734. }
  9735. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9736. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9737. filenametemp[i+1] = 0;
  9738. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9739. if(port == 0)
  9740. port = 21;
  9741. do
  9742. {
  9743. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9744. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9745. sleep(3);
  9746. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9747. if(!isSuccess)
  9748. {
  9749. DEBUG_INFO("Diagnostics fail.\n");
  9750. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9751. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9752. sleep(retryIntervalInt);
  9753. }
  9754. else
  9755. {
  9756. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9757. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9758. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9759. }
  9760. retriesInt--;
  9761. }while((!isSuccess)&&(retriesInt >= 0));
  9762. }
  9763. end:
  9764. system("rm -f /mnt/*");
  9765. sleep(5);
  9766. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9767. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9768. interLock.isGetDiagnosticGoing = 0;
  9769. pthread_exit(NULL);
  9770. }
  9771. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9772. {
  9773. mtrace();
  9774. int result = FAIL;
  9775. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9776. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9777. {
  9778. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9779. locallistVersion = -1;
  9780. }
  9781. else
  9782. {
  9783. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9784. OCPP_getListVerion();
  9785. }
  9786. //from db.OCPP_getListVerion
  9787. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9788. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9789. sendGetLocalListVersionConfirmation(uuid,"");
  9790. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9791. return result;
  9792. }
  9793. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9794. {
  9795. mtrace();
  9796. int result = FAIL;
  9797. int connectorIdInt=-1;
  9798. int tempIndex = 0;
  9799. int connectorIdIsNULL, chargingProfileIsNULL;
  9800. char comfirmstr[20]={0};
  9801. char cmdBuf[512];
  9802. json_object *RemoteStartTransaction;
  9803. FILE *fp;
  9804. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9805. if(server_pending == TRUE)
  9806. {
  9807. return 0;
  9808. }
  9809. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9810. RemoteStartTransaction = json_tokener_parse(payload);
  9811. if(!is_error(RemoteStartTransaction))
  9812. {
  9813. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9814. {
  9815. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9816. }
  9817. else
  9818. {
  9819. connectorIdIsNULL = TRUE;
  9820. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9821. {
  9822. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9823. {
  9824. connectorIdIsNULL = FALSE;
  9825. connectorIdInt = (gun_index+1);
  9826. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9827. break;
  9828. }
  9829. }
  9830. }
  9831. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9832. {
  9833. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9834. // Required data
  9835. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9836. // Optional data
  9837. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9838. {
  9839. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9840. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9841. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9842. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9843. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9844. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9845. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9846. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9847. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9848. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9849. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9850. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9851. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9852. {
  9853. 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")));
  9854. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9855. 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"));
  9856. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9857. 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"));
  9858. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9859. 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")));
  9860. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9861. {
  9862. 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++)
  9863. {
  9864. 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"));
  9865. 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"));
  9866. 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)
  9867. 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"));
  9868. }
  9869. }
  9870. }
  9871. }
  9872. else
  9873. {
  9874. chargingProfileIsNULL = TRUE;
  9875. }
  9876. }
  9877. }
  9878. else
  9879. {
  9880. connectorIdIsNULL = TRUE;
  9881. }
  9882. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9883. {
  9884. DEBUG_WARN("Connector id is NULL\n.");
  9885. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9886. goto end;
  9887. }
  9888. /*
  9889. enum _SYSTEM_STATUS
  9890. {
  9891. S_BOOTING = 0,
  9892. S_IDLE, = 1
  9893. S_AUTHORIZING, = 2
  9894. S_REASSIGN_CHECK, = 3
  9895. S_REASSIGN, = 4
  9896. S_PRECHARGE, = 5
  9897. S_PREPARING_FOR_EV, = 6
  9898. S_PREPARING_FOR_EVSE, = 7
  9899. S_CHARGING, = 8
  9900. S_TERMINATING, = 9
  9901. S_COMPLETE, = 10
  9902. S_ALARM, = 11
  9903. S_FAULT = 12
  9904. }
  9905. */
  9906. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9907. {
  9908. //check Transaction active
  9909. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9910. {
  9911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9912. {
  9913. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9914. }
  9915. else
  9916. {
  9917. tempIndex = connectorIdInt -1;
  9918. }
  9919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9920. {
  9921. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9922. {
  9923. 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))
  9924. {
  9925. //Reserved
  9926. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9927. }
  9928. 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))
  9929. {
  9930. //Reserved
  9931. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9932. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9933. goto end;
  9934. }
  9935. else
  9936. {
  9937. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9938. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9939. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9940. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9941. {
  9942. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9943. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9944. goto end;
  9945. }
  9946. }//END FOR ELSE
  9947. }
  9948. }// END FOR CHAdeMO_QUANTITY
  9949. }
  9950. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9951. {
  9952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9953. {
  9954. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9955. }
  9956. else
  9957. {
  9958. tempIndex = connectorIdInt -1;
  9959. }
  9960. for (int index = 0; index < CCS_QUANTITY; index++)
  9961. {
  9962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9963. {
  9964. 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))
  9965. {
  9966. //Reserved
  9967. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9968. }
  9969. 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))
  9970. {
  9971. //Reserved
  9972. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9973. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9974. goto end;
  9975. }
  9976. else
  9977. {
  9978. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9979. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9980. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9981. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9982. {
  9983. DEBUG_WARN("CCS connector not allow start\n.");
  9984. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9985. goto end;
  9986. }
  9987. }// END FOR ELSE
  9988. }
  9989. }// END FOR CCS_QUANTITY
  9990. }
  9991. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9992. {
  9993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9994. {
  9995. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9996. }
  9997. else
  9998. {
  9999. tempIndex = connectorIdInt -1;
  10000. }
  10001. for (int index = 0; index < GB_QUANTITY; index++)
  10002. {
  10003. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10004. {
  10005. 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))
  10006. {
  10007. //Reserved
  10008. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10009. }
  10010. 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))
  10011. {
  10012. //Reserved
  10013. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10014. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10015. goto end;
  10016. }
  10017. else
  10018. {
  10019. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10020. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10021. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10022. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10023. {
  10024. DEBUG_WARN("GB connector not allow start\n.");
  10025. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10026. goto end;
  10027. }
  10028. }// END FOR ELSE
  10029. }
  10030. } // END FOR GB_QUANTITY
  10031. }
  10032. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10033. {
  10034. tempIndex = connectorIdInt -1;
  10035. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10036. {
  10037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10038. {
  10039. 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))
  10040. {
  10041. //Reserved
  10042. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10043. }
  10044. 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))
  10045. {
  10046. //Reserved
  10047. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10049. goto end;
  10050. }
  10051. else
  10052. {
  10053. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10054. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10055. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10056. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10057. {
  10058. DEBUG_WARN("GB connector not allow start\n.");
  10059. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10060. goto end;
  10061. }
  10062. }// END FOR ELSE
  10063. }
  10064. } // END FOR GB_QUANTITY
  10065. }
  10066. else
  10067. {
  10068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10069. {
  10070. tempIndex = 2;
  10071. }
  10072. else
  10073. {
  10074. tempIndex = connectorIdInt -1;
  10075. }
  10076. for (int index = 0; index < AC_QUANTITY; index++)
  10077. {
  10078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10079. {
  10080. 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))
  10081. {
  10082. //Reserved
  10083. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10084. }
  10085. 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))
  10086. {
  10087. //Reserved
  10088. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10090. goto end;
  10091. }
  10092. else
  10093. {
  10094. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10095. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10096. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10097. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10098. {
  10099. DEBUG_WARN("AC connector not allow start\n.");
  10100. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10101. goto end;
  10102. }
  10103. }//END FOR ELSE
  10104. }
  10105. }// END FOR AC_QUANTITY
  10106. }
  10107. if(chargingProfileIsNULL == FALSE)
  10108. {
  10109. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10110. {
  10111. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10113. //memset idTag
  10114. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10115. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10116. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10118. // Save profile to file
  10119. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10120. system(cmdBuf);
  10121. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10122. fp = fopen(cmdBuf, "w");
  10123. 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));
  10124. fclose(fp);
  10125. }
  10126. else
  10127. {
  10128. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10130. }
  10131. }
  10132. else
  10133. {
  10134. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10136. //memset idTag
  10137. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10138. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10139. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10141. }
  10142. }
  10143. else
  10144. {
  10145. DEBUG_WARN("Connector id over\n.");
  10146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10147. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10148. }
  10149. end:
  10150. json_object_put(RemoteStartTransaction);
  10151. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10152. {
  10153. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10154. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10155. }
  10156. //OCPP send RemoteStartConfirmation by first.
  10157. sendRemoteStartConfirmation(uuid, comfirmstr);
  10158. return result;
  10159. }
  10160. int handleRemoteStartRequest(char *uuid, char *payload)
  10161. {
  10162. mtrace();
  10163. int result = PASS;
  10164. int connectorIdInt=-1;
  10165. int tempIndex = 0;
  10166. char comfirmstr[20]={0};
  10167. char cmdBuf[512];
  10168. json_object *RemoteStartTransaction;
  10169. FILE *fp;
  10170. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10171. if(server_pending == TRUE)
  10172. {
  10173. result = FAIL;
  10174. }
  10175. RemoteStartTransaction = json_tokener_parse(payload);
  10176. if(!is_error(RemoteStartTransaction))
  10177. {
  10178. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10179. {
  10180. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10181. }
  10182. else
  10183. {
  10184. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10185. {
  10186. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10187. {
  10188. connectorIdInt = (gun_index+1);
  10189. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10190. break;
  10191. }
  10192. }
  10193. }
  10194. if(connectorIdInt == 0)
  10195. {
  10196. DEBUG_WARN("Connector id shall not equal 0.\n");
  10197. result = FAIL;
  10198. }
  10199. else if(connectorIdInt == -1)
  10200. {
  10201. DEBUG_INFO("Connector id does not specific.\n");
  10202. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10203. {
  10204. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10205. // Required data
  10206. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10207. // Optional data
  10208. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10209. {
  10210. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10211. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10212. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10213. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10214. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10215. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10216. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10217. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10218. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10219. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10220. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10221. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10222. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10223. {
  10224. 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")));
  10225. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10226. 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"));
  10227. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10228. 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"));
  10229. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10230. 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")));
  10231. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10232. {
  10233. 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++)
  10234. {
  10235. 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"));
  10236. 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"));
  10237. 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)
  10238. 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"));
  10239. }
  10240. }
  10241. }
  10242. }
  10243. else
  10244. {
  10245. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10246. }
  10247. }
  10248. }
  10249. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10250. {
  10251. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10252. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10253. // Required data
  10254. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10255. // Optional data
  10256. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10257. {
  10258. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10259. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10260. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10261. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10262. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10263. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10264. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10265. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10266. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10267. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10268. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10269. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10270. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10271. {
  10272. 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")));
  10273. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10274. 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"));
  10275. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10276. 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"));
  10277. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10278. 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")));
  10279. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10280. {
  10281. 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++)
  10282. {
  10283. 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"));
  10284. 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"));
  10285. 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)
  10286. 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"));
  10287. }
  10288. }
  10289. }
  10290. }
  10291. else
  10292. {
  10293. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10294. }
  10295. }
  10296. else
  10297. {
  10298. DEBUG_WARN("Connector id is over maximun value.\n");
  10299. result = FAIL;
  10300. }
  10301. }
  10302. if(result == PASS)
  10303. {
  10304. if(connectorIdInt > 0)
  10305. {
  10306. //check Transaction active
  10307. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10308. {
  10309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10310. {
  10311. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10312. }
  10313. else
  10314. {
  10315. tempIndex = connectorIdInt -1;
  10316. }
  10317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10318. {
  10319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10320. {
  10321. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10322. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10323. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10324. {
  10325. //Reserved
  10326. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10327. }
  10328. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10329. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10330. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10331. {
  10332. //Reserved
  10333. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10335. goto end;
  10336. }
  10337. else
  10338. {
  10339. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10340. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10341. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10342. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10343. {
  10344. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10345. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10346. goto end;
  10347. }
  10348. }//END FOR ELSE
  10349. }
  10350. }// END FOR CHAdeMO_QUANTITY
  10351. }
  10352. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10353. {
  10354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10355. {
  10356. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10357. }
  10358. else
  10359. {
  10360. tempIndex = connectorIdInt -1;
  10361. }
  10362. for (int index = 0; index < CCS_QUANTITY; index++)
  10363. {
  10364. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10365. {
  10366. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10367. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10368. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10369. {
  10370. //Reserved
  10371. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10372. }
  10373. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10374. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10375. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10376. {
  10377. //Reserved
  10378. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10379. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10380. goto end;
  10381. }
  10382. else
  10383. {
  10384. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10385. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10386. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10387. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10388. {
  10389. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10390. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10391. goto end;
  10392. }
  10393. }// END FOR ELSE
  10394. }
  10395. }// END FOR CCS_QUANTITY
  10396. }
  10397. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10398. {
  10399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10400. {
  10401. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10402. }
  10403. else
  10404. {
  10405. tempIndex = connectorIdInt -1;
  10406. }
  10407. for (int index = 0; index < GB_QUANTITY; index++)
  10408. {
  10409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10410. {
  10411. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10412. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10413. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10414. {
  10415. //Reserved
  10416. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10417. }
  10418. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10419. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10420. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10421. {
  10422. //Reserved
  10423. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10424. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10425. goto end;
  10426. }
  10427. else
  10428. {
  10429. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10430. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10431. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10432. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10433. {
  10434. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10435. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10436. goto end;
  10437. }
  10438. }// END FOR ELSE
  10439. }
  10440. } // END FOR GB_QUANTITY
  10441. }
  10442. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10443. {
  10444. tempIndex = connectorIdInt -1;
  10445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10446. {
  10447. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10448. {
  10449. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10450. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10451. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10452. {
  10453. //Reserved
  10454. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10455. }
  10456. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10457. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10458. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10459. {
  10460. //Reserved
  10461. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10462. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10463. goto end;
  10464. }
  10465. else
  10466. {
  10467. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10468. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10469. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10470. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10471. {
  10472. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10473. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10474. goto end;
  10475. }
  10476. }// END FOR ELSE
  10477. }
  10478. } // END FOR GB_QUANTITY
  10479. }
  10480. else
  10481. {
  10482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10483. {
  10484. tempIndex = 2;
  10485. }
  10486. else
  10487. {
  10488. tempIndex = connectorIdInt -1;
  10489. }
  10490. for (int index = 0; index < AC_QUANTITY; index++)
  10491. {
  10492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10493. {
  10494. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10495. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10496. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10497. {
  10498. //Reserved
  10499. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10500. }
  10501. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10502. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10503. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10504. {
  10505. //Reserved
  10506. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10507. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10508. goto end;
  10509. }
  10510. else
  10511. {
  10512. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10513. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10514. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10515. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10516. {
  10517. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10519. goto end;
  10520. }
  10521. }//END FOR ELSE
  10522. }
  10523. }// END FOR AC_QUANTITY
  10524. }
  10525. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10526. {
  10527. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10528. {
  10529. // Save profile to file
  10530. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10531. system(cmdBuf);
  10532. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10533. fp = fopen(cmdBuf, "w");
  10534. 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));
  10535. fclose(fp);
  10536. }
  10537. else
  10538. {
  10539. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10540. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10541. goto end;
  10542. }
  10543. }
  10544. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10545. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10546. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10547. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10548. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10550. }
  10551. else
  10552. {
  10553. uint8_t isHasIdleConnector = FALSE;
  10554. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10555. {
  10556. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10557. {
  10558. isHasIdleConnector = TRUE;
  10559. break;
  10560. }
  10561. }
  10562. if(isHasIdleConnector == TRUE)
  10563. {
  10564. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10565. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10566. {
  10567. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10568. {
  10569. // Save profile to file
  10570. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10571. system(cmdBuf);
  10572. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10573. fp = fopen(cmdBuf, "w");
  10574. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10575. fclose(fp);
  10576. refreshStartTimer(&clientTime.RemoteStartWait);
  10577. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10578. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10579. }
  10580. else
  10581. {
  10582. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10583. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10584. }
  10585. }
  10586. else
  10587. {
  10588. refreshStartTimer(&clientTime.RemoteStartWait);
  10589. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10590. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10591. }
  10592. }
  10593. else
  10594. {
  10595. DEBUG_INFO("There is not any connector is idle.\n");
  10596. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10597. }
  10598. }
  10599. }
  10600. else
  10601. {
  10602. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10603. }
  10604. end:
  10605. json_object_put(RemoteStartTransaction);
  10606. sendRemoteStartConfirmation(uuid, comfirmstr);
  10607. return result;
  10608. }
  10609. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10610. {
  10611. mtrace();
  10612. int result = FAIL;
  10613. int match = FALSE;
  10614. int GunNO = 0;
  10615. int tempIndex = 0;
  10616. int transactionIdInt=0;
  10617. int transactionIdIsNULL= TRUE;
  10618. char comfirmstr[20];
  10619. json_object *RemoteStopTransaction;
  10620. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10621. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10622. if(server_pending == TRUE)
  10623. {
  10624. return 0;
  10625. }
  10626. RemoteStopTransaction = json_tokener_parse(payload);
  10627. if(!is_error(RemoteStopTransaction))
  10628. {
  10629. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10630. {
  10631. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10632. transactionIdIsNULL = FALSE;
  10633. }
  10634. }
  10635. json_object_put(RemoteStopTransaction);
  10636. if(transactionIdIsNULL == FALSE)
  10637. {
  10638. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10639. {
  10640. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10641. {
  10642. //check Transaction active
  10643. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10644. {
  10645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10646. {
  10647. tempIndex = ((gun_index==2) ? 1: 0);
  10648. }
  10649. else
  10650. {
  10651. tempIndex = gun_index;
  10652. }
  10653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10654. {
  10655. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10656. {
  10657. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10658. {
  10659. match = TRUE;
  10660. GunNO = gun_index;
  10661. }
  10662. }
  10663. }// END FOR CHAdeMO_QUANTITY
  10664. }
  10665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10666. {
  10667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10668. {
  10669. tempIndex = ((gun_index==2) ? 1: 0);
  10670. }
  10671. else
  10672. {
  10673. tempIndex = gun_index;
  10674. }
  10675. for (int index = 0; index < CCS_QUANTITY; index++)
  10676. {
  10677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10678. {
  10679. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10680. {
  10681. match = TRUE;
  10682. GunNO = gun_index;
  10683. }
  10684. }
  10685. }// END FOR CCS_QUANTITY
  10686. }
  10687. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10688. {
  10689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10690. {
  10691. tempIndex = ((gun_index==2) ? 1: 0);
  10692. }
  10693. else
  10694. {
  10695. tempIndex = gun_index;
  10696. }
  10697. for (int index = 0; index < GB_QUANTITY; index++)
  10698. {
  10699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10700. {
  10701. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10702. {
  10703. match = TRUE;
  10704. GunNO = gun_index;
  10705. }
  10706. }
  10707. }// END FOR GB_QUANTITY
  10708. }
  10709. else if(gunType[gun_index] == GUN_TYPE_DO)
  10710. {
  10711. tempIndex = gun_index;
  10712. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10713. {
  10714. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10715. {
  10716. 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
  10717. {
  10718. match = TRUE;
  10719. GunNO = gun_index;
  10720. }
  10721. }
  10722. }// END FOR GB_QUANTITY
  10723. }
  10724. else
  10725. {
  10726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10727. {
  10728. tempIndex = 2;
  10729. }
  10730. else
  10731. {
  10732. tempIndex = gun_index;
  10733. }
  10734. for (int index = 0; index < AC_QUANTITY; index++)
  10735. {
  10736. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10737. {
  10738. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10739. {
  10740. match = TRUE;
  10741. GunNO = gun_index;
  10742. }
  10743. }
  10744. }// END FOR CHAdeMO_QUANTITY
  10745. } // END FOR AC ELSE
  10746. }// CHECK IF ResponseTransactionId == transactionIdInt
  10747. }//END FOR
  10748. if( match == TRUE)
  10749. {
  10750. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10751. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10752. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10753. }
  10754. else
  10755. {
  10756. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10757. }
  10758. }
  10759. else
  10760. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10761. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10762. return result;
  10763. }
  10764. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10765. {
  10766. mtrace();
  10767. int result = FAIL;
  10768. int connectorIdInt=0, reservationIdInt=0;
  10769. int tempIndex = 0;
  10770. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10771. char comfirmstr[20]={0};
  10772. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10773. int c = 0;
  10774. char *loc;
  10775. //char *ptr;
  10776. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10777. strcpy(sstrtemp, stringtrimspace(payload));
  10778. //***(1)connectorId ****/
  10779. c=0;
  10780. loc = strstr(sstrtemp, "connectorId");
  10781. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10782. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10783. {
  10784. sstr[c] = loc[strlen("connectorId")+2+c];
  10785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10786. c++;
  10787. }
  10788. sstr[c] = '\0';
  10789. connectorIdInt = atoi(sstr);
  10790. //***(2)expiryDate ****/
  10791. loc = strstr(sstrtemp, "expiryDate");
  10792. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10793. c = 0;
  10794. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10795. {
  10796. sstr[c] = loc[3+strlen("expiryDate")+c];
  10797. c++;
  10798. }
  10799. sstr[c] = '\0';
  10800. strcpy(expiryDatestr, sstr);
  10801. //***(3)idTag ****/
  10802. loc = strstr(sstrtemp, "idTag");
  10803. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10804. c = 0;
  10805. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10806. {
  10807. sstr[c] = loc[3+strlen("idTag")+c];
  10808. c++;
  10809. }
  10810. sstr[c] = '\0';
  10811. strcpy(idTagstr, sstr);
  10812. //***(4)parentIdTag ****/
  10813. loc = strstr(sstrtemp, "parentIdTag");
  10814. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10815. c = 0;
  10816. if(loc == NULL)
  10817. {
  10818. strcpy(parentIdTagstr, "");
  10819. }
  10820. else
  10821. {
  10822. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10823. {
  10824. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10825. c++;
  10826. }
  10827. sstr[c] = '\0';
  10828. strcpy(parentIdTagstr, sstr);
  10829. }
  10830. //***(5)reservationId ****/
  10831. c=0;
  10832. loc = strstr(sstrtemp, "reservationId");
  10833. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10834. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10835. {
  10836. sstr[c] = loc[strlen("reservationId")+2+c];
  10837. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10838. c++;
  10839. }
  10840. sstr[c] = '\0';
  10841. reservationIdInt = atoi(sstr);
  10842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10843. /*
  10844. enum SYSTEM_STATUS
  10845. {
  10846. SYS_MODE_BOOTING = 0,
  10847. SYS_MODE_IDLE = 1,
  10848. SYS_MODE_AUTHORIZING = 2,
  10849. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10850. SYS_MODE_REASSIGN = 4,
  10851. SYS_MODE_PREPARING = 5,
  10852. SYS_MODE_PREPARE_FOR_EV = 6,
  10853. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10854. SYS_MODE_CHARGING = 8,
  10855. SYS_MODE_TERMINATING = 9,
  10856. SYS_MODE_COMPLETE = 10,
  10857. SYS_MODE_ALARM = 11,
  10858. SYS_MODE_FAULT = 12,
  10859. SYS_MODE_RESERVATION = 13,
  10860. SYS_MODE_BOOKING = 14,
  10861. SYS_MODE_MAINTAIN = 15,
  10862. SYS_MODE_DEBUG = 16,
  10863. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10864. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10865. SYS_MODE_UPDATE = 19
  10866. };
  10867. */
  10868. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10869. {
  10870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10871. goto end;
  10872. }
  10873. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10874. {
  10875. //check Transaction active
  10876. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10877. {
  10878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10879. {
  10880. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10881. }
  10882. else
  10883. {
  10884. tempIndex = connectorIdInt -1;
  10885. }
  10886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10887. {
  10888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10889. {
  10890. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10891. {
  10892. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10893. {
  10894. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10895. {
  10896. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10898. }
  10899. 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'))
  10900. {
  10901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10902. }
  10903. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10904. {
  10905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10906. }
  10907. else
  10908. {
  10909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10910. }
  10911. }
  10912. 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
  10913. {
  10914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10915. }
  10916. }
  10917. else
  10918. {
  10919. //replace reservation
  10920. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10922. }
  10923. }
  10924. } // END FOR CHAdeMO_QUANTITY
  10925. }
  10926. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10927. {
  10928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10929. {
  10930. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10931. }
  10932. else
  10933. {
  10934. tempIndex = connectorIdInt -1;
  10935. }
  10936. for (int index = 0; index < CCS_QUANTITY; index++)
  10937. {
  10938. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10939. {
  10940. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10941. {
  10942. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10943. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10944. {
  10945. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10946. {
  10947. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10949. }
  10950. 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'))
  10951. {
  10952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10953. }
  10954. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10955. {
  10956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10957. }
  10958. else
  10959. {
  10960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10961. }
  10962. }
  10963. 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
  10964. {
  10965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10966. }
  10967. }
  10968. else
  10969. {
  10970. //replace reservation
  10971. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10973. }
  10974. }
  10975. } // END FOR CCS_QUANTITY
  10976. }
  10977. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10978. {
  10979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10980. {
  10981. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10982. }
  10983. else
  10984. {
  10985. tempIndex = connectorIdInt -1;
  10986. }
  10987. for (int index = 0; index < GB_QUANTITY; index++)
  10988. {
  10989. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10990. {
  10991. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10992. {
  10993. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10994. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10995. {
  10996. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10997. {
  10998. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11000. }
  11001. 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'))
  11002. {
  11003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11004. }
  11005. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11006. {
  11007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11008. }
  11009. else
  11010. {
  11011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11012. }
  11013. }
  11014. 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
  11015. {
  11016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11017. }
  11018. }
  11019. else
  11020. {
  11021. //replace reservation
  11022. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11024. }
  11025. }
  11026. }// END FOR GB_QUANTITY
  11027. }
  11028. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11029. {
  11030. tempIndex = connectorIdInt -1;
  11031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11032. {
  11033. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11034. {
  11035. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11036. {
  11037. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11038. 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
  11039. {
  11040. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11041. {
  11042. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11044. }
  11045. 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'))
  11046. {
  11047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11048. }
  11049. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11050. {
  11051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11052. }
  11053. else
  11054. {
  11055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11056. }
  11057. }
  11058. 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
  11059. {
  11060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11061. }
  11062. }
  11063. else
  11064. {
  11065. //replace reservation
  11066. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11068. }
  11069. }
  11070. }// END FOR GB_QUANTITY
  11071. }
  11072. else
  11073. {
  11074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11075. {
  11076. tempIndex = 2;
  11077. }
  11078. else
  11079. {
  11080. tempIndex = (connectorIdInt -1);
  11081. }
  11082. for (int index = 0; index < AC_QUANTITY; index++)
  11083. {
  11084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11085. {
  11086. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11087. {
  11088. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11089. {
  11090. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11091. {
  11092. 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))
  11093. {
  11094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11095. }
  11096. else
  11097. {
  11098. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11100. }
  11101. }
  11102. 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'))
  11103. {
  11104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11105. }
  11106. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11107. {
  11108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11109. }
  11110. else
  11111. {
  11112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11113. }
  11114. }
  11115. 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
  11116. {
  11117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11118. }
  11119. }
  11120. else
  11121. {
  11122. //replace reservation
  11123. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11125. }
  11126. }
  11127. } // END FOR AC_QUANTITY
  11128. }
  11129. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11130. }
  11131. else if(connectorIdInt == 0)
  11132. {
  11133. //check Transaction active
  11134. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11135. {
  11136. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11137. {
  11138. 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'))
  11139. {
  11140. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11141. goto end;
  11142. }
  11143. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11144. {
  11145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11146. goto end;
  11147. }
  11148. 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
  11149. {
  11150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11151. goto end;
  11152. }
  11153. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11154. {
  11155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11156. goto end;
  11157. }
  11158. }
  11159. }// END FOR CHAdeMO_QUANTITY
  11160. for (int index = 0; index < CCS_QUANTITY; index++)
  11161. {
  11162. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11163. {
  11164. 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'))
  11165. {
  11166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11167. goto end;
  11168. }
  11169. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11170. {
  11171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11172. goto end;
  11173. }
  11174. 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
  11175. {
  11176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11177. goto end;
  11178. }
  11179. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11180. {
  11181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11182. goto end;
  11183. }
  11184. }
  11185. } // END FOR CCS_QUANTITY
  11186. for (int index = 0; index < GB_QUANTITY; index++)
  11187. {
  11188. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11189. {
  11190. 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'))
  11191. {
  11192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11193. goto end;
  11194. }
  11195. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11196. {
  11197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11198. goto end;
  11199. }
  11200. 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
  11201. {
  11202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11203. goto end;
  11204. }
  11205. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11206. {
  11207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11208. goto end;
  11209. }
  11210. }
  11211. } // END FOR GB_QUANTITY
  11212. for (int index = 0; index < AC_QUANTITY; index++)
  11213. {
  11214. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11215. {
  11216. 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'))
  11217. {
  11218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11219. goto end;
  11220. }
  11221. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11222. {
  11223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11224. goto end;
  11225. }
  11226. 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
  11227. {
  11228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11229. goto end;
  11230. }
  11231. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11232. {
  11233. 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))
  11234. {
  11235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11236. goto end;
  11237. }
  11238. }
  11239. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11240. {
  11241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11242. goto end;
  11243. }
  11244. }
  11245. }// END FOR AC_QUANTITY
  11246. //The connectorId is 0
  11247. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11248. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11249. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11250. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11251. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11252. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11253. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11254. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11255. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11256. result = TRUE;
  11257. return result;
  11258. }
  11259. else
  11260. {
  11261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11262. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11263. }
  11264. if(strcmp(comfirmstr,"Accepted") == 0)
  11265. {
  11266. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11267. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11268. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11269. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11270. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11271. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11272. result = TRUE;
  11273. return result;
  11274. }
  11275. end:
  11276. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11277. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11278. return result;
  11279. }
  11280. int handleResetRequest(char *uuid, char *payload)
  11281. {
  11282. mtrace();
  11283. int result = FAIL;
  11284. char sstr[10]={0},sstrtemp[30]={ 0 };
  11285. char typestr[10]={0};
  11286. char comfirmstr[20]={0};
  11287. int c = 0;
  11288. char *loc;
  11289. DEBUG_INFO("handleResetRequest...\n");
  11290. strcpy(sstrtemp, stringtrimspace(payload));
  11291. loc = strstr(sstrtemp, "type");
  11292. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11293. c = 0;
  11294. while (loc[3+strlen("type")+c] != '\"')
  11295. {
  11296. sstr[c] = loc[3+strlen("type")+c];
  11297. c++;
  11298. }
  11299. sstr[c] = '\0';
  11300. strcpy(typestr,sstr);
  11301. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11302. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11303. {
  11304. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11305. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11306. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11307. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11308. }
  11309. else
  11310. {
  11311. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11312. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11313. result = PASS;
  11314. }
  11315. sendResetConfirmation(uuid, comfirmstr);
  11316. return result;
  11317. }
  11318. int handleSendLocalListRequest(char *uuid, char *payload)
  11319. {
  11320. mtrace();
  11321. int result = FAIL;
  11322. char comfirmstr[20];
  11323. int checkState_Faulted = FALSE;
  11324. json_object *SendLocalList;
  11325. DEBUG_INFO("handleSendLocalListRequest...\n");
  11326. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11327. {
  11328. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11329. goto end;
  11330. }
  11331. //check Charge Point state
  11332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11333. {
  11334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11335. {
  11336. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11337. }
  11338. }
  11339. for (int index = 0; index < CCS_QUANTITY; index++)
  11340. {
  11341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11342. {
  11343. checkState_Faulted = TRUE; //OCPP Status
  11344. }
  11345. }
  11346. for (int index = 0; index < GB_QUANTITY; index++)
  11347. {
  11348. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11349. {
  11350. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11351. }
  11352. }
  11353. //check Charge Point state
  11354. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11355. {
  11356. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11357. {
  11358. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11359. }
  11360. }
  11361. //check Charge Point state
  11362. for (int index = 0; index < AC_QUANTITY; index++)
  11363. {
  11364. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11365. {
  11366. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11367. }
  11368. }
  11369. if(checkState_Faulted == TRUE)
  11370. {
  11371. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11372. goto end;
  11373. }
  11374. // Parsing payload
  11375. SendLocalList = json_tokener_parse(payload);
  11376. if(!is_error(SendLocalList))
  11377. {
  11378. // Required data
  11379. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11380. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11381. // Optional data
  11382. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11383. {
  11384. //Check UpdateType
  11385. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11386. {
  11387. //Local list full update
  11388. DEBUG_INFO("Local list full update.\n");
  11389. OCPP_getListVerion();
  11390. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11391. {
  11392. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11393. goto end;
  11394. }
  11395. OCPP_cleanLocalList();
  11396. }
  11397. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11398. {
  11399. //Local list different update
  11400. DEBUG_INFO("Local list different update.\n");
  11401. OCPP_getListVerion();
  11402. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11403. {
  11404. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11405. goto end;
  11406. }
  11407. }
  11408. else
  11409. {
  11410. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11411. goto end;
  11412. }
  11413. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11414. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11415. {
  11416. 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")));
  11417. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11418. {
  11419. 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")));
  11420. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11421. 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")));
  11422. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11423. 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")));
  11424. }
  11425. // Add to db
  11426. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11427. {
  11428. //Local list full update
  11429. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11430. idx,
  11431. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11432. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11433. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11434. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11435. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11436. // update list
  11437. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11438. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11439. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11440. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11441. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11442. }
  11443. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11444. {
  11445. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11446. idx,
  11447. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11448. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11449. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11450. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11451. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11452. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11453. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11454. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11455. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11456. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11457. }
  11458. }
  11459. }
  11460. else
  11461. {
  11462. //Check UpdateType
  11463. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11464. {
  11465. //Local list full update
  11466. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11467. OCPP_cleanLocalList();
  11468. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11469. goto end;
  11470. }
  11471. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11472. {
  11473. //Local list different update
  11474. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11475. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11476. goto end;
  11477. }
  11478. }
  11479. result = PASS;
  11480. }
  11481. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11482. end:
  11483. json_object_put(SendLocalList);
  11484. sendSendLocalListConfirmation(uuid, comfirmstr);
  11485. return result;
  11486. }
  11487. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11488. {
  11489. mtrace();
  11490. int result = FAIL;
  11491. struct StructSetChargingProfile SetProfileReq = {0};
  11492. int tempchargingProfileIdInt;
  11493. int chargingSchedulePeriodCount = 0;
  11494. char comfirmstr[20]={0};
  11495. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11496. char rmFileCmd[128]={0};
  11497. int profileQuantity = 0;
  11498. json_object *SetChargingProfile;
  11499. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11500. SetChargingProfile = json_tokener_parse(payload);
  11501. if(!is_error(SetChargingProfile))
  11502. {
  11503. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11504. {
  11505. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11506. }
  11507. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11508. {
  11509. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11510. {
  11511. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11512. }
  11513. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11514. {
  11515. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11516. }
  11517. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11518. {
  11519. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11520. }
  11521. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11522. {
  11523. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11524. }
  11525. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11526. {
  11527. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11528. }
  11529. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11530. {
  11531. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11532. }
  11533. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11534. {
  11535. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11536. }
  11537. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11538. {
  11539. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11540. }
  11541. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11542. {
  11543. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11544. {
  11545. 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")));
  11546. }
  11547. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11548. {
  11549. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11550. }
  11551. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11552. {
  11553. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11554. }
  11555. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11556. {
  11557. 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")));
  11558. }
  11559. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11560. {
  11561. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11562. if(chargingSchedulePeriodCount <= 10)
  11563. {
  11564. 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++)
  11565. {
  11566. 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)
  11567. {
  11568. 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"));
  11569. }
  11570. 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)
  11571. {
  11572. 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"));
  11573. }
  11574. 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)
  11575. {
  11576. 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"));
  11577. }
  11578. }
  11579. }
  11580. }
  11581. }
  11582. }
  11583. }
  11584. // Profile periods quantity check
  11585. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11586. {
  11587. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11588. goto end;
  11589. }
  11590. // Check invalid limit
  11591. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11592. {
  11593. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11594. {
  11595. 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)))) ||
  11596. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11597. {
  11598. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11599. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11600. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11601. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11602. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11603. goto end;
  11604. }
  11605. }
  11606. }
  11607. else
  11608. {
  11609. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11610. {
  11611. 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))
  11612. {
  11613. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11614. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11615. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11616. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11617. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11618. goto end;
  11619. }
  11620. }
  11621. }
  11622. // Profile purpose info check
  11623. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11624. {
  11625. FILE *fp;
  11626. char dataLine[4096]={0};
  11627. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11628. if(SetProfileReq.ConnectorId != 0)
  11629. {
  11630. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11631. goto end;
  11632. }
  11633. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11634. if (!fp)
  11635. {
  11636. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11637. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11638. }
  11639. else
  11640. {
  11641. while(fscanf(fp, "%s", dataLine) != EOF)
  11642. {
  11643. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11644. {
  11645. profileQuantity += 1;
  11646. }
  11647. }
  11648. }
  11649. fclose(fp);
  11650. }
  11651. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11652. {
  11653. FILE *fp;
  11654. char dataLine[4096]={0};
  11655. char filename[128]={0};
  11656. int tmpProfileQuantity;
  11657. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11658. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11659. {
  11660. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11661. goto end;
  11662. }
  11663. if(SetProfileReq.ConnectorId == 0)
  11664. {
  11665. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11666. {
  11667. tmpProfileQuantity = 0;
  11668. memset(filename, 0, ARRAY_SIZE(filename));
  11669. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11670. fp = fopen(filename, "r");
  11671. if (!fp)
  11672. {
  11673. DEBUG_INFO("%s does not create.\n", filename);
  11674. fp = fopen(filename, "w+");
  11675. }
  11676. else
  11677. {
  11678. while(fscanf(fp, "%s", dataLine) != EOF)
  11679. {
  11680. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11681. {
  11682. tmpProfileQuantity += 1;
  11683. }
  11684. }
  11685. }
  11686. fclose(fp);
  11687. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11688. }
  11689. }
  11690. else
  11691. {
  11692. memset(filename, 0, ARRAY_SIZE(filename));
  11693. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11694. fp = fopen(filename, "r");
  11695. if (!fp)
  11696. {
  11697. DEBUG_INFO("%s does not create.\n", filename);
  11698. fp = fopen(filename, "w+");
  11699. }
  11700. else
  11701. {
  11702. while(fscanf(fp, "%s", dataLine) != EOF)
  11703. {
  11704. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11705. {
  11706. profileQuantity += 1;
  11707. }
  11708. }
  11709. }
  11710. fclose(fp);
  11711. }
  11712. }
  11713. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11714. {
  11715. int isMatchTransactiodId= FALSE;
  11716. FILE *fp;
  11717. char dataLine[4096]={0};
  11718. char filename[128]={0};
  11719. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11720. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11721. if(SetProfileReq.ConnectorId == 0)
  11722. {
  11723. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11724. goto end;
  11725. }
  11726. int tempIndex = 0;
  11727. //check Transaction active
  11728. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11729. {
  11730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11731. {
  11732. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11733. }
  11734. else
  11735. {
  11736. tempIndex = SetProfileReq.ConnectorId -1;
  11737. }
  11738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11739. {
  11740. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11741. {
  11742. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11743. {
  11744. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11745. {
  11746. isMatchTransactiodId = TRUE;
  11747. break;
  11748. }
  11749. }
  11750. }
  11751. }
  11752. }
  11753. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11754. {
  11755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11756. {
  11757. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11758. }
  11759. else
  11760. {
  11761. tempIndex = SetProfileReq.ConnectorId -1;
  11762. }
  11763. for (int index = 0; index < CCS_QUANTITY; index++)
  11764. {
  11765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11766. {
  11767. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11768. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11769. {
  11770. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11771. {
  11772. isMatchTransactiodId = TRUE;
  11773. break;
  11774. }
  11775. }
  11776. }
  11777. }
  11778. }
  11779. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11780. {
  11781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11782. {
  11783. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11784. }
  11785. else
  11786. {
  11787. tempIndex = SetProfileReq.ConnectorId -1;
  11788. }
  11789. for (int index = 0; index < GB_QUANTITY; index++)
  11790. {
  11791. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11792. {
  11793. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11794. {
  11795. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11796. {
  11797. isMatchTransactiodId = TRUE;
  11798. break;
  11799. }
  11800. }
  11801. }
  11802. }
  11803. }
  11804. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11805. {
  11806. tempIndex = SetProfileReq.ConnectorId -1;
  11807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11808. {
  11809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11810. {
  11811. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11812. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11813. {
  11814. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11815. {
  11816. isMatchTransactiodId = TRUE;
  11817. break;
  11818. }
  11819. }
  11820. }
  11821. }
  11822. }
  11823. else
  11824. {
  11825. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11826. {
  11827. tempIndex = 2;
  11828. }
  11829. else
  11830. {
  11831. tempIndex = (SetProfileReq.ConnectorId -1);
  11832. }
  11833. for (int index = 0; index < AC_QUANTITY; index++)
  11834. {
  11835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11836. {
  11837. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11838. {
  11839. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11840. {
  11841. isMatchTransactiodId = TRUE;
  11842. break;
  11843. }
  11844. }
  11845. }
  11846. }
  11847. }
  11848. //check Transaction active
  11849. if(isMatchTransactiodId == FALSE)
  11850. {
  11851. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11852. goto end;
  11853. }
  11854. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11855. {
  11856. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11857. goto end;
  11858. }
  11859. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11860. fp = fopen(filename, "r");
  11861. if (!fp)
  11862. {
  11863. DEBUG_INFO("%s does not create.\n", filename);
  11864. fp = fopen(filename, "w+");
  11865. }
  11866. else
  11867. {
  11868. //Check Charging Profile Count
  11869. while(fscanf(fp, "%s", dataLine) != EOF)
  11870. {
  11871. //DEBUG_INFO("word=%s\n",word);
  11872. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11873. {
  11874. profileQuantity += 1;
  11875. }
  11876. }
  11877. }
  11878. fclose(fp);
  11879. }
  11880. // Check ChargeProfileMaxStackLevel
  11881. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11882. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11883. {
  11884. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11885. goto end;
  11886. }
  11887. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11888. {
  11889. FILE *fp;
  11890. char dataLine[4096]={0};
  11891. char fnametemp[128]={0};
  11892. int tmpProfileQuantity;
  11893. //Check ChargePointMaxProfile.json exit
  11894. profileQuantity = 0;
  11895. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11896. {
  11897. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11898. //Check Charging Profile Count
  11899. tmpProfileQuantity = 0;
  11900. while(fscanf(fp, "%s", dataLine) != EOF)
  11901. {
  11902. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11903. {
  11904. profileQuantity += 1;
  11905. tmpProfileQuantity += 1;
  11906. }
  11907. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11908. }
  11909. fclose(fp);
  11910. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11911. }
  11912. //Check TxDefaultProfile_%d.json
  11913. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11914. {
  11915. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11916. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11917. if((access(fnametemp,F_OK))!=-1)
  11918. {
  11919. fp = fopen(fnametemp, "r");
  11920. //Check Charging Profile Count
  11921. tmpProfileQuantity = 0;
  11922. while(fscanf(fp, "%s", dataLine) != EOF)
  11923. {
  11924. //DEBUG_INFO("word=%s\n",word);
  11925. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11926. {
  11927. profileQuantity += 1;
  11928. tmpProfileQuantity += 1;
  11929. }
  11930. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11931. }
  11932. fclose(fp);
  11933. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11934. }
  11935. }
  11936. //Check TxProfile_%d.json
  11937. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11938. {
  11939. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11940. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11941. if((access(fnametemp,F_OK))!=-1)
  11942. {
  11943. fp = fopen(fnametemp, "r");
  11944. //Check Charging Profile Count
  11945. tmpProfileQuantity = 0;
  11946. while(fscanf(fp, "%s", dataLine) != EOF)
  11947. {
  11948. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11949. {
  11950. profileQuantity += 1;
  11951. tmpProfileQuantity += 1;
  11952. }
  11953. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11954. }
  11955. fclose(fp);
  11956. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11957. }
  11958. }
  11959. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11960. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11961. {
  11962. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11963. goto end;
  11964. }
  11965. }
  11966. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11967. //**********************************Write to File********************************************************/
  11968. {
  11969. FILE *infile;
  11970. FILE *outfile;
  11971. char dataLine[4096]={0};
  11972. char filename[128]={0};
  11973. int chkChar=0;
  11974. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11975. {
  11976. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11977. {
  11978. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11979. }
  11980. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11981. {
  11982. if(SetProfileReq.ConnectorId==0)
  11983. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11984. else
  11985. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11986. }
  11987. else
  11988. {
  11989. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11990. }
  11991. infile = fopen (filename, "r");
  11992. outfile = fopen (tempfile, "w");
  11993. chkChar = fgetc(infile);
  11994. rewind(infile);
  11995. if(chkChar == EOF)
  11996. {
  11997. // Profile is empty
  11998. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11999. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12000. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12001. fclose(infile);
  12002. fclose(outfile);
  12003. sprintf(rmFileCmd,"rm -f %s",filename);
  12004. system(rmFileCmd);
  12005. rename(tempfile, filename);
  12006. }
  12007. else
  12008. {
  12009. // Profile is not empty
  12010. int ChargingProfileAdded = FALSE;
  12011. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12012. {
  12013. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12014. json_object *tmpChargingProfile;
  12015. tmpChargingProfile = json_tokener_parse(dataLine);
  12016. if(!is_error(SetChargingProfile))
  12017. {
  12018. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12019. {
  12020. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12021. {
  12022. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12023. }
  12024. }
  12025. }
  12026. json_object_put(tmpChargingProfile);
  12027. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12028. {
  12029. if(ChargingProfileAdded == FALSE)
  12030. {
  12031. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12032. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12033. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12034. ChargingProfileAdded = TRUE;
  12035. }
  12036. }
  12037. else
  12038. {
  12039. fprintf(outfile,"%s\n",dataLine);
  12040. if(ChargingProfileAdded == FALSE)
  12041. {
  12042. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12043. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12044. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12045. ChargingProfileAdded = TRUE;
  12046. }
  12047. }
  12048. } // end of while loop
  12049. fclose(infile);
  12050. fclose(outfile);
  12051. sprintf(rmFileCmd,"rm -f %s",filename);
  12052. system(rmFileCmd);
  12053. rename(tempfile, filename);
  12054. }
  12055. }
  12056. sleep(1);
  12057. result = TRUE;
  12058. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12059. }
  12060. end:
  12061. json_object_put(SetChargingProfile);
  12062. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12063. {
  12064. if(SetProfileReq.ConnectorId == 0)
  12065. {
  12066. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12067. {
  12068. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12069. }
  12070. }
  12071. else
  12072. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12073. }
  12074. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12075. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12076. return result;
  12077. }
  12078. int handleTriggerMessageRequest(char *uuid, char *payload)
  12079. {
  12080. mtrace();
  12081. int result = FAIL;
  12082. int connectorIdIsNULL = FALSE;
  12083. int connectorIdInt =0;
  12084. char sstr[40]={0},sstrtemp[100]={ 0 };
  12085. char requestedMessagestr[40]={0};
  12086. char comfirmstr[20]={0};
  12087. int c = 0;
  12088. char *loc;
  12089. DEBUG_INFO("handleTriggerMessageRequest\n");
  12090. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12091. strcpy(sstrtemp, stringtrimspace(payload));
  12092. c = 0;
  12093. loc = strstr(sstrtemp, "requestedMessage");
  12094. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12095. {
  12096. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12097. c++;
  12098. }
  12099. sstr[c] = '\0';
  12100. strcpy(requestedMessagestr, sstr);
  12101. c = 0;
  12102. loc = strstr(sstrtemp, "connectorId");
  12103. if(loc == NULL)
  12104. {
  12105. connectorIdIsNULL = TRUE;
  12106. }
  12107. else
  12108. {
  12109. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12110. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12111. {
  12112. sstr[c] = loc[strlen("connectorId")+2+c];
  12113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12114. c++;
  12115. }
  12116. sstr[c] = '\0';
  12117. connectorIdInt = atoi(sstr);
  12118. }
  12119. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12120. {
  12121. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12122. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12123. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12124. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12125. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12126. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12127. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12128. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12129. {
  12130. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12131. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12132. return TRUE;
  12133. }
  12134. else
  12135. {
  12136. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12137. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12138. }
  12139. }
  12140. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12141. {
  12142. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12143. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12144. return TRUE;
  12145. }
  12146. //==========================
  12147. // Trigger message
  12148. //==========================
  12149. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12150. {
  12151. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12152. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12153. {
  12154. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12155. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12156. }
  12157. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12158. }
  12159. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12160. {
  12161. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12162. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12163. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12164. }
  12165. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12166. {
  12167. //sendBootNotificationRequest();
  12168. server_sign = FALSE;
  12169. }
  12170. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12171. {
  12172. refreshStartTimer(&clientTime.Heartbeat);
  12173. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12174. }
  12175. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12176. {
  12177. if(connectorIdIsNULL == FALSE)
  12178. {
  12179. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12180. {
  12181. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12182. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12183. }
  12184. }
  12185. else
  12186. {
  12187. for(int idx=0;idx< gunTotalNumber;idx++)
  12188. {
  12189. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12190. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12191. }
  12192. }
  12193. }
  12194. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12195. {
  12196. if(connectorIdIsNULL == FALSE)
  12197. {
  12198. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12199. {
  12200. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12201. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12202. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12203. }
  12204. }
  12205. else
  12206. {
  12207. for(int idx=0;idx< gunTotalNumber;idx++)
  12208. {
  12209. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12210. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12211. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12212. }
  12213. }
  12214. }
  12215. return result;
  12216. }
  12217. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12218. {
  12219. mtrace();
  12220. int result = FAIL;
  12221. int connectorIdInt =0;
  12222. char comfirmstr[20]={0};
  12223. int tempIndex = 0;
  12224. json_object *UnlockConnector;
  12225. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12226. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12227. UnlockConnector = json_tokener_parse(payload);
  12228. if(!is_error(UnlockConnector))
  12229. {
  12230. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12231. {
  12232. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12233. }
  12234. }
  12235. json_object_put(UnlockConnector);
  12236. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12237. if(gunTotalNumber == 0)
  12238. {
  12239. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12240. goto end;
  12241. }
  12242. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12243. {
  12244. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12245. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12246. goto end;
  12247. }
  12248. else
  12249. {
  12250. //check Transaction active
  12251. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12252. {
  12253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12254. {
  12255. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12256. }
  12257. else
  12258. {
  12259. tempIndex = connectorIdInt -1;
  12260. }
  12261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12262. {
  12263. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12264. {
  12265. //stop Transaction
  12266. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12267. }
  12268. }
  12269. }
  12270. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12271. {
  12272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12273. {
  12274. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12275. }
  12276. else
  12277. {
  12278. tempIndex = connectorIdInt -1;
  12279. }
  12280. for (int index = 0; index < CCS_QUANTITY; index++)
  12281. {
  12282. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12283. {
  12284. //stop Transaction
  12285. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12286. }
  12287. }
  12288. }
  12289. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12290. {
  12291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12292. {
  12293. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12294. }
  12295. else
  12296. {
  12297. tempIndex = connectorIdInt -1;
  12298. }
  12299. for (int index = 0; index < GB_QUANTITY; index++)
  12300. {
  12301. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12302. {
  12303. //stop Transaction
  12304. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12305. }
  12306. }
  12307. }
  12308. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12309. {
  12310. tempIndex = connectorIdInt -1;
  12311. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12312. {
  12313. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12314. {
  12315. //stop Transaction
  12316. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12317. }
  12318. }
  12319. }
  12320. else
  12321. {
  12322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12323. {
  12324. tempIndex = 2;
  12325. }
  12326. else
  12327. {
  12328. tempIndex = connectorIdInt-1;
  12329. }
  12330. for (int index = 0; index < AC_QUANTITY; index++)
  12331. {
  12332. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12333. {
  12334. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12335. }
  12336. }
  12337. }
  12338. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12339. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12340. result = TRUE;
  12341. return result;
  12342. }
  12343. end:
  12344. //json_object_put(obj); --- remove temporally
  12345. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12346. return result;
  12347. }
  12348. static char UpdateFirmwarepayloadData[300]={0};
  12349. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12350. {
  12351. mtrace();
  12352. int result = FAIL;
  12353. pthread_t t;
  12354. sendUpdateFirmwareConfirmation(uuid);
  12355. memset(UpdateFirmwarepayloadData, 0, 300);
  12356. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12357. if(!interLock.isUpdateFirmwareGoing)
  12358. {
  12359. interLock.isUpdateFirmwareGoing = 1;
  12360. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12361. sleep(1);
  12362. }
  12363. else
  12364. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12365. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12366. return result;
  12367. }
  12368. void *UpdateFirmwareProcess(void *data)
  12369. {
  12370. pthread_detach(pthread_self());
  12371. mtrace();
  12372. int retriesInt =0, retryIntervalInt=0;
  12373. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12374. int port=0;
  12375. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12376. int isSuccess = 0;
  12377. char ftpbuf[512];
  12378. char temp[100];
  12379. char * pch;
  12380. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12381. json_object *UpdateFirmware;
  12382. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12383. if(!is_error(UpdateFirmware))
  12384. {
  12385. // Required data
  12386. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12387. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12388. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12389. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12390. // Optional data
  12391. if(json_object_object_get(UpdateFirmware, "retries"))
  12392. {
  12393. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12394. }
  12395. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12396. {
  12397. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12398. }
  12399. }
  12400. json_object_put(UpdateFirmware);
  12401. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12402. memset(path, 0, ARRAY_SIZE(path));
  12403. // Wait retrieveData
  12404. if(strlen(retrieveDatestr) > 10)
  12405. {
  12406. do
  12407. {
  12408. sleep(1);
  12409. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12410. }
  12411. // Ready to download
  12412. system("rm -f /mnt/*");
  12413. if(strncmp(locationstr,"http", 4) == 0)
  12414. {
  12415. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12416. sprintf(ftppath,"/%s", path);
  12417. DEBUG_INFO("locationstr: %s\n", locationstr);
  12418. DEBUG_INFO("protocol: %s\n",protocol);
  12419. DEBUG_INFO("host: %s\n",host);
  12420. DEBUG_INFO("path: %s\n",path);
  12421. DEBUG_INFO("ftppath: %s\n",ftppath);
  12422. int ftppathlen=strlen(ftppath);
  12423. int i=1;
  12424. char filenametemp[50];
  12425. while(i < ftppathlen)
  12426. {
  12427. int len=ftppathlen-i;
  12428. if(ftppath[len]== 47) // '/' ascll code: 47
  12429. {
  12430. DEBUG_INFO("compare '/' all right\n");
  12431. break;
  12432. }
  12433. i=i+1;
  12434. }
  12435. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12436. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12437. filenametemp[i+1] = 0;
  12438. do
  12439. {
  12440. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12441. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12442. sleep(1);
  12443. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12444. if(!isSuccess)
  12445. {
  12446. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12447. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12448. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12449. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12450. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12451. }
  12452. else
  12453. {
  12454. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12455. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12456. }
  12457. retriesInt--;
  12458. }while((isSuccess == 0)&&(retriesInt >= 0));
  12459. }
  12460. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12461. {
  12462. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12463. memset(temp, 0, ARRAY_SIZE(temp));
  12464. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12465. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12466. int ftppathlen=strlen(ftpbuf);
  12467. int i=1;
  12468. char filenametemp[50];
  12469. while(i < ftppathlen)
  12470. {
  12471. int len=ftppathlen-i;
  12472. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12473. {
  12474. DEBUG_INFO(" compare '/' all right\n");
  12475. break;
  12476. }
  12477. i=i+1;
  12478. }
  12479. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12480. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12481. filenametemp[i+1] = 0;
  12482. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12483. pch=strchr(temp,'@');
  12484. if(pch==NULL)
  12485. {
  12486. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12487. protocol, host, &port, path);
  12488. strcpy(user,"anonymous");
  12489. strcpy(password,"");
  12490. }
  12491. else
  12492. {
  12493. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12494. protocol, user, password, host, &port, path);
  12495. }
  12496. sscanf(host,"%[^/]%s",host1, path1);
  12497. sprintf(ftppath,"%s", path1);
  12498. //DEBUG_INFO("protocol =%s\n",protocol);
  12499. //DEBUG_INFO("user =%s\n",user);
  12500. //DEBUG_INFO("password =%s\n",password);
  12501. //DEBUG_INFO("host1 =%s\n",host1);
  12502. //DEBUG_INFO("port =%d\n",port);
  12503. //DEBUG_INFO("path1 =%s\n",path1);
  12504. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12505. //ftpFile(host, user, password, port, ftppath, fname);
  12506. //download firmware pthred
  12507. if(port == 0)
  12508. {
  12509. port = 21;
  12510. }
  12511. do
  12512. {
  12513. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12514. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12515. sleep(1);
  12516. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12517. if(!isSuccess)
  12518. {
  12519. //BulldogUtil.sleepMs(interval*1000);
  12520. DEBUG_INFO("Update firmware request and download file fail.\n");
  12521. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12522. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12523. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12524. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12525. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12526. }
  12527. else
  12528. {
  12529. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12530. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12531. }
  12532. retriesInt--;
  12533. }while((!isSuccess)&&(retriesInt >= 0));
  12534. }
  12535. else
  12536. {
  12537. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12538. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12539. sleep(1);
  12540. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12541. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12542. }
  12543. // OCPPPH only, must announce CSU upgrade firmware
  12544. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12545. interLock.isUpdateFirmwareGoing = 0;
  12546. pthread_exit(NULL);
  12547. }
  12548. int handleCertificateSignedRequest(char *uuid, char *payload)
  12549. {
  12550. mtrace();
  12551. int result = PASS;
  12552. json_object *CertificateSigned;
  12553. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12554. CertificateSigned = json_tokener_parse(payload);
  12555. if(!is_error(CertificateSigned))
  12556. {
  12557. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12558. }
  12559. json_object_put(CertificateSigned);
  12560. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12561. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12562. fclose(fp);
  12563. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12564. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12565. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12566. sendCertificateSignedConfirmation(uuid);
  12567. return result;
  12568. }
  12569. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12570. {
  12571. mtrace();
  12572. int result = PASS;
  12573. json_object *DeleteCertificate;
  12574. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12575. DeleteCertificate = json_tokener_parse(payload);
  12576. if(!is_error(DeleteCertificate))
  12577. {
  12578. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12579. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12580. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12581. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12582. }
  12583. json_object_put(DeleteCertificate);
  12584. /*
  12585. * TODO: Delete certificateSigned process
  12586. */
  12587. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12588. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12589. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12590. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12591. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12592. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12593. sendDeleteCertificateConfirmation(uuid);
  12594. return result;
  12595. }
  12596. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12597. {
  12598. mtrace();
  12599. int result = PASS;
  12600. json_object *ExtendedTriggerMessage;
  12601. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12602. ExtendedTriggerMessage = json_tokener_parse(payload);
  12603. if(!is_error(ExtendedTriggerMessage))
  12604. {
  12605. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12606. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12607. {
  12608. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12609. }
  12610. else
  12611. {
  12612. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12613. }
  12614. }
  12615. json_object_put(ExtendedTriggerMessage);
  12616. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12617. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12618. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12619. {
  12620. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12621. }
  12622. else
  12623. {
  12624. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12625. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12626. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12627. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12628. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12629. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12630. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12631. {
  12632. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12633. }
  12634. else
  12635. {
  12636. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12637. }
  12638. }
  12639. sendExtendedTriggerMessageConfirmation(uuid);
  12640. //==========================
  12641. // Trigger message
  12642. //==========================
  12643. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12644. {
  12645. //sendBootNotificationRequest();
  12646. server_sign = FALSE;
  12647. }
  12648. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12649. {
  12650. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12651. }
  12652. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12653. {
  12654. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12655. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12656. {
  12657. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12658. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12659. }
  12660. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12661. }
  12662. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12663. {
  12664. refreshStartTimer(&clientTime.Heartbeat);
  12665. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12666. }
  12667. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12668. {
  12669. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12670. {
  12671. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12672. }
  12673. else
  12674. {
  12675. for(int idx=0;idx< gunTotalNumber;idx++)
  12676. {
  12677. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12678. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12679. }
  12680. }
  12681. }
  12682. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12683. {
  12684. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12685. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12686. {
  12687. 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\" &");
  12688. }
  12689. }
  12690. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12691. {
  12692. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12693. {
  12694. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12695. }
  12696. else
  12697. {
  12698. for(int idx=0;idx< gunTotalNumber;idx++)
  12699. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12700. }
  12701. }
  12702. return result;
  12703. }
  12704. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12705. {
  12706. mtrace();
  12707. int result = PASS;
  12708. json_object *GetInstalledCertificateIds;
  12709. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12710. GetInstalledCertificateIds = json_tokener_parse(payload);
  12711. if(!is_error(GetInstalledCertificateIds))
  12712. {
  12713. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12714. }
  12715. json_object_put(GetInstalledCertificateIds);
  12716. /*
  12717. * TODO: Return installed certificate process
  12718. */
  12719. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12720. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12721. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12722. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12723. sendGetInstalledCertificateIdsConfirmation(uuid);
  12724. return result;
  12725. }
  12726. int handleGetLogRequest(char *uuid, char *payload)
  12727. {
  12728. mtrace();
  12729. int result = PASS;
  12730. json_object *GetLog;
  12731. DEBUG_INFO("handleGetLogRequest...\n");
  12732. GetLog = json_tokener_parse(payload);
  12733. if(!is_error(GetLog))
  12734. {
  12735. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12736. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12737. if(json_object_object_get(GetLog, "retries") != NULL)
  12738. {
  12739. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12740. }
  12741. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12742. {
  12743. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12744. }
  12745. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12746. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12747. {
  12748. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12749. }
  12750. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12751. {
  12752. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12753. }
  12754. }
  12755. json_object_put(GetLog);
  12756. /*
  12757. * TODO: Upload log process
  12758. */
  12759. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12760. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12761. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12762. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12763. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12764. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12765. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12766. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12767. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12768. sendGetLogConfirmation(uuid);
  12769. return result;
  12770. }
  12771. int handleInstallCertificateRequest(char *uuid, char *payload)
  12772. {
  12773. mtrace();
  12774. int result = PASS;
  12775. json_object *InstallCertificate;
  12776. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12777. InstallCertificate = json_tokener_parse(payload);
  12778. if(!is_error(InstallCertificate))
  12779. {
  12780. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12781. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12782. /*
  12783. * TODO: Install certificate process
  12784. */
  12785. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12786. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12787. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12788. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12789. sendInstallCertificateConfirmation(uuid);
  12790. }
  12791. json_object_put(InstallCertificate);
  12792. return result;
  12793. }
  12794. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12795. {
  12796. mtrace();
  12797. int result = PASS;
  12798. json_object *SignedUpdateFirmware;
  12799. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12800. SignedUpdateFirmware = json_tokener_parse(payload);
  12801. if(!is_error(SignedUpdateFirmware))
  12802. {
  12803. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12804. {
  12805. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12806. }
  12807. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12808. {
  12809. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12810. }
  12811. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12812. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12813. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12814. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12815. {
  12816. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12817. }
  12818. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12819. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12820. }
  12821. json_object_put(SignedUpdateFirmware);
  12822. /*
  12823. * TODO: Upgrade firmware process
  12824. */
  12825. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12826. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12827. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12828. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12829. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12830. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12831. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12832. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12833. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12834. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12835. sendInstallCertificateConfirmation(uuid);
  12836. return result;
  12837. }
  12838. int handleUnknownRequest(char *uuid, char *payload)
  12839. {
  12840. mtrace();
  12841. int result = PASS;
  12842. DEBUG_INFO("handleUnknownRequest...\n");
  12843. sendUnknownConfirmation(uuid);
  12844. result = PASS;
  12845. return result;
  12846. }
  12847. //==========================================
  12848. // Handle server response routine
  12849. //==========================================
  12850. void handleAuthorizeResponse(char *payload, int gun_index)
  12851. {
  12852. mtrace();
  12853. char expiryDatestr[30]={0};
  12854. char parentIdTagstr[20]={0};
  12855. char statusstr[20]={0};
  12856. int expiryDateISNULL=FALSE;
  12857. int parentIdTagISNULL=FALSE;
  12858. DEBUG_INFO("handleAuthorizeResponse...\n");
  12859. json_object *Authorize;
  12860. Authorize = json_tokener_parse(payload);
  12861. if(!is_error(Authorize))
  12862. {
  12863. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12864. {
  12865. // Required data
  12866. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12867. // Optional data
  12868. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12869. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12870. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12871. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12872. }
  12873. }
  12874. json_object_put(Authorize);
  12875. if(expiryDateISNULL == FALSE)
  12876. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12877. if(parentIdTagISNULL == FALSE)
  12878. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12879. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12880. //Update idTag information to authorization cache if supproted
  12881. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12882. {
  12883. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12884. }
  12885. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12886. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12887. authorizeRetryTimes = 0;
  12888. }
  12889. void handleBootNotificationResponse(char *payload, int gun_index)
  12890. {
  12891. mtrace();
  12892. char statusStr[12]={0};
  12893. char currentTimeStr[30]={0};
  12894. int intervalInt = 0;
  12895. DEBUG_INFO("handleBootNotificationResponse...\n");
  12896. json_object *BootNotification;
  12897. BootNotification = json_tokener_parse(payload);
  12898. if(!is_error(BootNotification))
  12899. {
  12900. // Required data
  12901. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12902. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12903. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12904. }
  12905. json_object_put(BootNotification);
  12906. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12907. BootNotificationInterval = intervalInt;
  12908. HeartBeatWaitTime = intervalInt;
  12909. //write back to ShmOCPP16DataPH->BootNotification
  12910. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12911. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12912. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12913. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12914. {
  12915. if((intervalInt == 0) || (intervalInt >= 10))
  12916. {
  12917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12918. HeartBeatWaitTime = intervalInt;
  12919. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12920. }
  12921. server_sign = TRUE;
  12922. server_pending =FALSE;
  12923. }
  12924. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12925. {
  12926. server_pending = TRUE;
  12927. }
  12928. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12929. srand(time(NULL));
  12930. refreshStartTimer(&clientTime.Heartbeat);
  12931. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12932. SetOcppConnStatus(TRUE);
  12933. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12934. }
  12935. void handleDataTransferResponse(char *payload, int gun_index)
  12936. {
  12937. json_object *DataTransfer = json_tokener_parse(payload);
  12938. if(!is_error(DataTransfer))
  12939. {
  12940. // Required data
  12941. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12942. // Optional data
  12943. if(json_object_object_get(DataTransfer, "data") != NULL)
  12944. {
  12945. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12946. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12947. if(!is_error(Data))
  12948. {
  12949. if(json_object_object_get(Data, "msgId") != NULL)
  12950. {
  12951. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12952. {
  12953. 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")));
  12954. }
  12955. }
  12956. }
  12957. json_object_put(Data);
  12958. }
  12959. }
  12960. json_object_put(DataTransfer);
  12961. }
  12962. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12963. {
  12964. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12965. //struct json_object *obj;
  12966. // obj = json_tokener_parse(payload);
  12967. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12968. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12969. //No fields are defined.
  12970. }
  12971. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12972. {
  12973. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12974. //struct json_object *obj;
  12975. // obj = json_tokener_parse(payload);
  12976. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12977. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12978. //No fields are defined.
  12979. }
  12980. void handleHeartbeatResponse(char *payload, int gun_index)
  12981. {
  12982. mtrace();
  12983. DEBUG_INFO("handleHeartbeatResponse...\n");
  12984. json_object *Heartbeat;
  12985. Heartbeat = json_tokener_parse(payload);
  12986. if(!is_error(Heartbeat))
  12987. {
  12988. // Required data
  12989. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12990. }
  12991. json_object_put(Heartbeat);
  12992. if(FirstHeartBeat == 0)
  12993. {
  12994. FirstHeartBeat = 1;
  12995. DEBUG_INFO("FirstHeartBeat \n");
  12996. }
  12997. HeartBeatWithNOResponse = 0;
  12998. refreshStartTimer(&clientTime.Heartbeat);
  12999. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13000. }
  13001. void handleMeterValuesResponse(char *payload, int gun_index)
  13002. {
  13003. mtrace();
  13004. DEBUG_INFO("handleMeterValuesResponse...\n");
  13005. isQueueSendable = 1;
  13006. }
  13007. void handleStartTransactionResponse(char *payload, int gun_index)
  13008. {
  13009. mtrace();
  13010. //int transactionIdInt = 0;
  13011. FILE *outfile;
  13012. char data[100]={0};
  13013. DEBUG_INFO("handleStartTransactionResponse...\n");
  13014. json_object *StartTransaction;
  13015. StartTransaction = json_tokener_parse(payload);
  13016. if(!is_error(StartTransaction))
  13017. {
  13018. // Required data
  13019. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13020. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13021. // Optional data
  13022. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13023. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13024. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13025. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13026. }
  13027. json_object_put(StartTransaction);
  13028. isQueueSendable = 1;
  13029. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13030. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13031. //-----------Start : write to the Queue TransactionId file -----------------//
  13032. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13033. {}
  13034. else
  13035. {
  13036. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13037. if(log == NULL)
  13038. {
  13039. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13040. return ;
  13041. }
  13042. else
  13043. {
  13044. fclose(log);
  13045. }
  13046. }
  13047. // open file for writing
  13048. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13049. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13050. {
  13051. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13052. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13053. fputs(data, outfile);
  13054. fclose (outfile);
  13055. }
  13056. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13057. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13058. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13059. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13060. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13061. }
  13062. void handleStatusNotificationResponse(char *payload, int gun_index)
  13063. {
  13064. mtrace();
  13065. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13066. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13067. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13068. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13069. }
  13070. void handleStopTransactionnResponse(char *payload, int gun_index)
  13071. {
  13072. mtrace();
  13073. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13074. json_object *StopTransaction;
  13075. StopTransaction = json_tokener_parse(payload);
  13076. if(!is_error(StopTransaction))
  13077. {
  13078. // Optional data
  13079. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13080. {
  13081. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13082. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13084. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13085. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13086. }
  13087. }
  13088. json_object_put(StopTransaction);
  13089. isQueueSendable = 1;
  13090. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13091. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13092. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13093. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13094. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13095. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13096. }
  13097. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13098. {
  13099. mtrace();
  13100. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13101. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13102. }
  13103. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13104. {
  13105. mtrace();
  13106. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13107. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13108. }
  13109. void handleSignCertificateResponse(char *payload, int gun_index)
  13110. {
  13111. mtrace();
  13112. DEBUG_INFO("handleSignCertificateResponse...\n");
  13113. json_object *SignCertificate;
  13114. SignCertificate = json_tokener_parse(payload);
  13115. if(!is_error(SignCertificate))
  13116. {
  13117. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13118. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13119. }
  13120. json_object_put(SignCertificate);
  13121. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13122. }
  13123. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13124. {
  13125. mtrace();
  13126. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13127. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13128. }
  13129. //==========================================
  13130. // Handle Error routine
  13131. //==========================================
  13132. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13133. {
  13134. mtrace();
  13135. #ifdef SystemLogMessage
  13136. DEBUG_INFO("errorCode: %s\n", errorCode);
  13137. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13138. DEBUG_INFO("errorDetails: %s\n", payload);
  13139. #endif
  13140. }
  13141. //===============================================
  13142. // Common routine
  13143. //===============================================
  13144. int initialConfigurationTable(void)
  13145. {
  13146. //clock_t start_t, end_t, total_t;
  13147. FILE *fp;
  13148. FILE *outfile;
  13149. char str[512]={0};
  13150. char sstr[256]={0};
  13151. int c = 0;
  13152. char *loc;
  13153. int confVersion = 13;
  13154. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13155. //start_t = clock();
  13156. //printf("Starting of the program, start_t = %ld\n", start_t);
  13157. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13158. // Check configuration file size is correct
  13159. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13160. {
  13161. struct stat st;
  13162. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13163. if(st.st_size < 3100)
  13164. {
  13165. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13166. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13167. }
  13168. }
  13169. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13170. {
  13171. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13172. if(outfile == NULL)
  13173. {
  13174. DEBUG_INFO("Error opening file\n");
  13175. return FALSE;
  13176. }
  13177. /*Core Profile*/
  13178. //AllowOfflineTxForUnknownId
  13179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13183. //AuthorizationCacheEnabled
  13184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13188. //AuthorizeRemoteTxRequests
  13189. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13193. //BlinkRepeat
  13194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13198. //ClockAlignedDataInterval
  13199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13203. //ConnectionTimeOut
  13204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13208. //GetConfigurationMaxKeys
  13209. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13213. // HeartbeatInterval
  13214. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13218. // LightIntensity
  13219. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13223. // LocalAuthorizeOffline
  13224. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13228. // LocalPreAuthorize
  13229. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13233. // MaxEnergyOnInvalidId
  13234. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13238. // MeterValuesAlignedData
  13239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13242. 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" );
  13243. else
  13244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13246. // MeterValuesAlignedDataMaxLength
  13247. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13251. else
  13252. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13254. // MeterValuesSampledData
  13255. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13258. 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" );
  13259. else
  13260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13262. // MeterValuesSampledDataMaxLength
  13263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13267. else
  13268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13270. // MeterValueSampleInterval
  13271. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13272. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13273. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13275. // MinimumStatusDuration
  13276. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13279. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13281. // NumberOfConnectors
  13282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13285. {
  13286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13287. }
  13288. else
  13289. {
  13290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13291. }
  13292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13293. // ResetRetries
  13294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13298. // ConnectorPhaseRotation
  13299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13303. // ConnectorPhaseRotationMaxLength
  13304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13308. // StopTransactionOnEVSideDisconnect
  13309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13313. // StopTransactionOnInvalidId
  13314. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13315. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13318. // StopTxnAlignedData
  13319. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13323. // StopTxnAlignedDataMaxLength
  13324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13328. // StopTxnSampledData
  13329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13333. else
  13334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13336. // StopTxnSampledDataMaxLength
  13337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13340. {
  13341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13342. }
  13343. else
  13344. {
  13345. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13346. }
  13347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13348. // SupportedFeatureProfiles
  13349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13353. // SupportedFeatureProfilesMaxLength
  13354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13358. // TransactionMessageAttempts
  13359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13362. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13364. // TransactionMessageRetryInterval
  13365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13368. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13370. // UnlockConnectorOnEVSideDisconnect
  13371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13375. // WebSocketPingInterval
  13376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13380. // QueueOffLineMeterValues
  13381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13385. // AuthorizationKey
  13386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13390. // SecurityProfile
  13391. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13395. // DefaultPrice
  13396. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13400. // CustomDisplayCostAndPrice
  13401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13405. // CustomIdleFeeAfterStop
  13406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13410. // SystemUptimeSec
  13411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13415. // FreeVend
  13416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13420. // FreeVendIdtag
  13421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13425. // OcppServer
  13426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13428. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13430. // MaintainServer
  13431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13433. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13435. // StatusNotificationPeriodically
  13436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13440. // StatusNotificationInterval
  13441. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13445. // Configuration Version
  13446. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13450. //* Local Auth List Management Profile*/
  13451. #if 0
  13452. //For OCTT Test Case
  13453. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13455. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13456. #endif
  13457. #if 1
  13458. //LocalAuthListEnabled
  13459. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13460. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13461. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13463. #endif
  13464. //LocalAuthListMaxLength
  13465. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13466. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13469. //SendLocalListMaxLength
  13470. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13474. //ReserveConnectorZeroSupported
  13475. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13479. //* Smart Charging Profile */
  13480. //ChargeProfileMaxStackLevel
  13481. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13485. // ChargingScheduleAllowedChargingRateUnit
  13486. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13490. // ChargingScheduleMaxPeriods
  13491. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13492. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13493. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13495. // ConnectorSwitch3to1PhaseSupported
  13496. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13497. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13500. // MaxChargingProfilesInstalled
  13501. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13505. fclose(outfile);
  13506. }
  13507. else
  13508. {
  13509. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13510. char keystr[60]={0};
  13511. char readonlystr[10]={0};
  13512. char valuestr[256]={0};
  13513. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13514. if(fp == NULL) {
  13515. DEBUG_INFO("Error opening file");
  13516. return FALSE;
  13517. }
  13518. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13519. {
  13520. //DEBUG_INFO("Get Configuration \n");
  13521. if(strlen(str) > 0)
  13522. {
  13523. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13524. //*************************key*********************************/
  13525. if(strstr(str, "key") != NULL)
  13526. {
  13527. loc = strstr(str, "key");
  13528. c = 0;
  13529. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13530. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13531. {
  13532. sstr[c] = loc[strlen("key")+3+c];
  13533. c++;
  13534. }
  13535. sstr[c] = '\0';
  13536. strcpy(keystr,sstr);
  13537. }
  13538. //*************************readonly*********************************/
  13539. if(strstr(str, "readonly") != NULL)
  13540. {
  13541. loc = strstr(str, "readonly");
  13542. c = 0;
  13543. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13544. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13545. {
  13546. sstr[c] = loc[strlen("readonly")+2+c];
  13547. c++;
  13548. }
  13549. sstr[c] = '\0';
  13550. strcpy(readonlystr,sstr);
  13551. }
  13552. //*************************value*********************************/
  13553. if(strstr(str, "value") != NULL)
  13554. {
  13555. loc = strstr(str, "value");
  13556. c = 0;
  13557. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13558. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13559. {
  13560. sstr[c] = loc[strlen("value")+3+c];
  13561. c++;
  13562. }
  13563. sstr[c] = '\0';
  13564. strcpy(valuestr,sstr);
  13565. }
  13566. // DEBUG_INFO("keystr=%s\n",keystr);
  13567. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13568. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13569. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13570. {
  13571. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13573. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13574. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13575. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13576. }
  13577. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13578. {
  13579. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13580. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13582. }
  13583. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13584. {
  13585. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13586. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13587. }
  13588. if(strcmp(keystr, "BlinkRepeat") == 0)
  13589. {
  13590. //Charger.BlinkRepeat = Integer.parseInt(value);
  13591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13593. }
  13594. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13595. {
  13596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13597. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13598. }
  13599. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13600. {
  13601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13603. }
  13604. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13605. {
  13606. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13607. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13608. }
  13609. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13610. {
  13611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13612. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13613. HeartBeatWaitTime = atoi(valuestr);
  13614. }
  13615. if(strcmp(keystr, "LightIntensity") == 0)
  13616. {
  13617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13619. }
  13620. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13621. {
  13622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13624. }
  13625. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13626. {
  13627. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13629. }
  13630. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13631. {
  13632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13633. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13634. }
  13635. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13636. {
  13637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13639. }
  13640. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13641. {
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13643. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13644. }
  13645. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13646. {
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13649. }
  13650. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13651. {
  13652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13654. }
  13655. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13656. {
  13657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13659. }
  13660. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13661. {
  13662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13663. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13664. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13665. }
  13666. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13667. {
  13668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13670. }
  13671. if(strcmp(keystr, "ResetRetries") == 0)
  13672. {
  13673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13675. }
  13676. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13677. {
  13678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13680. }
  13681. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13682. {
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13685. }
  13686. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13687. {
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13690. }
  13691. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13692. {
  13693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13695. }
  13696. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13697. {
  13698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13700. }
  13701. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13702. {
  13703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13705. }
  13706. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13707. {
  13708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13710. }
  13711. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13712. {
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13714. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13715. }
  13716. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13717. {
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13720. }
  13721. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13722. {
  13723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13725. }
  13726. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13727. {
  13728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13730. TransactionMessageAttemptsValue = atoi(valuestr);
  13731. }
  13732. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13733. {
  13734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13736. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13737. }
  13738. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13739. {
  13740. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13741. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13742. }
  13743. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13744. {
  13745. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13747. }
  13748. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13749. {
  13750. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13751. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13752. }
  13753. if(strcmp(keystr, "AuthorizationKey") == 0)
  13754. {
  13755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13756. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13758. }
  13759. if(strcmp(keystr, "SecurityProfile") == 0)
  13760. {
  13761. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13762. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13764. }
  13765. if(strcmp(keystr, "DefaultPrice") == 0)
  13766. {
  13767. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13768. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13769. }
  13770. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13771. {
  13772. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13774. }
  13775. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13776. {
  13777. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13778. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13779. }
  13780. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13781. {
  13782. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13784. }
  13785. if(strcmp(keystr, "FreeVend") == 0)
  13786. {
  13787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13789. }
  13790. if(strcmp(keystr, "FreeVendIdtag") == 0)
  13791. {
  13792. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  13794. }
  13795. if(strcmp(keystr, "OcppServer") == 0)
  13796. {
  13797. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13798. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13799. }
  13800. if(strcmp(keystr, "MaintainServer") == 0)
  13801. {
  13802. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13803. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13804. }
  13805. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13806. {
  13807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13809. }
  13810. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13811. {
  13812. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13813. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13814. }
  13815. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13816. {
  13817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13818. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13819. }
  13820. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13821. {
  13822. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13823. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13824. }
  13825. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13826. {
  13827. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13829. }
  13830. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13831. {
  13832. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13833. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13834. }
  13835. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13836. {
  13837. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13839. }
  13840. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13841. {
  13842. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13843. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13844. }
  13845. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13846. {
  13847. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13848. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13849. }
  13850. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13851. {
  13852. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13854. }
  13855. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13856. {
  13857. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13858. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13859. }
  13860. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13861. {
  13862. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13863. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13864. }
  13865. }
  13866. }
  13867. fclose(fp);
  13868. }
  13869. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13870. {
  13871. return PASS;
  13872. }
  13873. else
  13874. {
  13875. return FAIL;
  13876. }
  13877. }
  13878. void StoreConfigurationTable(void)
  13879. {
  13880. FILE *outfile;
  13881. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13882. if(outfile == NULL)
  13883. {
  13884. DEBUG_INFO("Error opening file");
  13885. return ;
  13886. }
  13887. /*Core Profile*/
  13888. //AllowOfflineTxForUnknownId
  13889. /*
  13890. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13891. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13894. */
  13895. //DEBUG_INFO("data=%s\n",data);
  13896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13897. //AuthorizationCacheEnabled
  13898. /*
  13899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13902. */
  13903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13904. //AuthorizeRemoteTxRequests
  13905. /*
  13906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13909. */
  13910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13911. //BlinkRepeat
  13912. /*
  13913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13916. */
  13917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13918. //ClockAlignedDataInterval
  13919. /*
  13920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13923. */
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13925. //ConnectionTimeOut
  13926. /*
  13927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13930. */
  13931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13932. //GetConfigurationMaxKeys
  13933. /*
  13934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13937. */
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13939. // HeartbeatInterval
  13940. /*
  13941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13944. */
  13945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13946. // LightIntensity
  13947. /*
  13948. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13951. */
  13952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13953. // LocalAuthorizeOffline
  13954. /*
  13955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13958. */
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13960. // LocalPreAuthorize
  13961. /*
  13962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13965. */
  13966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13967. // MaxEnergyOnInvalidId
  13968. /*
  13969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13972. */
  13973. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13975. // MeterValuesAlignedData
  13976. /*
  13977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13980. */
  13981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13982. // MeterValuesAlignedDataMaxLength
  13983. /*
  13984. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13987. */
  13988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13989. // MeterValuesSampledData
  13990. /*
  13991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13994. */
  13995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13996. // MeterValuesSampledDataMaxLength
  13997. /*
  13998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14001. */
  14002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14003. // MeterValueSampleInterval
  14004. /*
  14005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14008. */
  14009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14010. // MinimumStatusDuration
  14011. /*
  14012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14015. */
  14016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14017. // NumberOfConnectors
  14018. /*
  14019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14022. {
  14023. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14024. }
  14025. else
  14026. {
  14027. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14028. }
  14029. */
  14030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14031. // ResetRetries
  14032. /*
  14033. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14036. */
  14037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14038. // ConnectorPhaseRotation
  14039. /*
  14040. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14043. */
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14045. // ConnectorPhaseRotationMaxLength
  14046. /*
  14047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14050. */
  14051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14052. // StopTransactionOnEVSideDisconnect
  14053. /*
  14054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14057. */
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14059. // StopTransactionOnInvalidId
  14060. /*
  14061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14064. */
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14066. // StopTxnAlignedData
  14067. /*
  14068. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14071. */
  14072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14073. // StopTxnAlignedDataMaxLength
  14074. /*
  14075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14078. */
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14080. // StopTxnSampledData
  14081. /*
  14082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14085. */
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14087. // StopTxnSampledDataMaxLength
  14088. /*
  14089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14092. */
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14094. // SupportedFeatureProfiles
  14095. /*
  14096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14099. */
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14101. // SupportedFeatureProfilesMaxLength
  14102. /*
  14103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14106. */
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14108. // TransactionMessageAttempts
  14109. /*
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14113. */
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14115. // TransactionMessageRetryInterval
  14116. /*
  14117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14120. */
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14122. // UnlockConnectorOnEVSideDisconnect
  14123. /*
  14124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14127. */
  14128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14129. // WebSocketPingInterval
  14130. /*
  14131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14134. */
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14136. // QueueOffLineMeterValues
  14137. /*
  14138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14141. */
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14143. // AuthorizationKey
  14144. /*
  14145. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14148. */
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14150. // SecurityProfile
  14151. /*
  14152. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14155. */
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14157. // DefaultPrice
  14158. /*
  14159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14162. */
  14163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14164. // CustomDisplayCostAndPrice
  14165. /*
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14169. */
  14170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14171. // CustomIdleFeeAfterStop
  14172. /*
  14173. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14176. */
  14177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14178. // SystemUptimeSec
  14179. /*
  14180. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14183. */
  14184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14185. // FreeVend
  14186. /*
  14187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14190. */
  14191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14192. // FreeVendIdtag
  14193. /*
  14194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14197. */
  14198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14199. // OcppServer
  14200. /*
  14201. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14204. */
  14205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14206. // MaintainServer
  14207. /*
  14208. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14211. */
  14212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14213. // StatusNotificationPeriodically
  14214. /*
  14215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14218. */
  14219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14220. // StatusNotificationInterval
  14221. /*
  14222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14225. */
  14226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14227. // ConfigurationVersion
  14228. /*
  14229. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14232. */
  14233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14234. //* Local Auth List Management Profile*/
  14235. //LocalAuthListEnabled
  14236. /*
  14237. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14238. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14240. */
  14241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14242. //LocalAuthListMaxLength
  14243. /*
  14244. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14247. */
  14248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14249. //SendLocalListMaxLength
  14250. /*
  14251. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14252. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14253. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14254. */
  14255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14256. //ReserveConnectorZeroSupported
  14257. /*
  14258. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14261. */
  14262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14263. //* Smart Charging Profile */
  14264. //ChargeProfileMaxStackLevel
  14265. /*
  14266. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14267. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14269. */
  14270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14271. // ChargingScheduleAllowedChargingRateUnit
  14272. /*
  14273. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14276. */
  14277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14278. // ChargingScheduleMaxPeriods
  14279. /*
  14280. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14281. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14283. */
  14284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14285. // ConnectorSwitch3to1PhaseSupported
  14286. /*
  14287. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14290. */
  14291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14292. // MaxChargingProfilesInstalled
  14293. /*
  14294. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14297. */
  14298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14299. fclose(outfile);
  14300. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14301. }
  14302. void getKeyValue(char *keyReq)
  14303. {
  14304. int isEmpty = FALSE;
  14305. int isKnowKey = FALSE;
  14306. DEBUG_INFO("keyReq = %s\n", keyReq);
  14307. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14308. isEmpty = TRUE;
  14309. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14310. {
  14311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14313. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14314. {
  14315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14316. }
  14317. else
  14318. {
  14319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14320. }
  14321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14322. isKnowKey = TRUE;
  14323. }
  14324. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14325. {
  14326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14328. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14329. {
  14330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14331. }
  14332. else
  14333. {
  14334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14335. }
  14336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14337. isKnowKey = TRUE;
  14338. }
  14339. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14340. {
  14341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14343. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14344. {
  14345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14346. }
  14347. else
  14348. {
  14349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14350. }
  14351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14352. isKnowKey = TRUE;
  14353. }
  14354. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14355. {
  14356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14358. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14359. {
  14360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14361. }
  14362. else
  14363. {
  14364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14365. }
  14366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14367. isKnowKey = TRUE;
  14368. }
  14369. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14370. {
  14371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14373. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14374. {
  14375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14376. }
  14377. else
  14378. {
  14379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14380. }
  14381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14382. isKnowKey = TRUE;
  14383. }
  14384. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14385. {
  14386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14388. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14389. {
  14390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14391. }
  14392. else
  14393. {
  14394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14395. }
  14396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14397. isKnowKey = TRUE;
  14398. }
  14399. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14400. {
  14401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14403. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14404. {
  14405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14406. }
  14407. else
  14408. {
  14409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14410. }
  14411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14412. isKnowKey = TRUE;
  14413. }
  14414. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14415. {
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14418. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14419. {
  14420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14421. }
  14422. else
  14423. {
  14424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14425. }
  14426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14427. isKnowKey = TRUE;
  14428. }
  14429. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14430. {
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14433. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14434. {
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14436. }
  14437. else
  14438. {
  14439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14440. }
  14441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14442. isKnowKey = TRUE;
  14443. }
  14444. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14445. {
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14448. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14449. {
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14451. }
  14452. else
  14453. {
  14454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14455. }
  14456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14457. isKnowKey = TRUE;
  14458. }
  14459. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14460. {
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14463. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14464. {
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14466. }
  14467. else
  14468. {
  14469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14470. }
  14471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14472. isKnowKey = TRUE;
  14473. }
  14474. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14475. {
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14479. {
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14481. }
  14482. else
  14483. {
  14484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14485. }
  14486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14487. isKnowKey = TRUE;
  14488. }
  14489. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14490. {
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14494. {
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14496. }
  14497. else
  14498. {
  14499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14500. }
  14501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14502. isKnowKey = TRUE;
  14503. }
  14504. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14505. {
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14509. {
  14510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14511. }
  14512. else
  14513. {
  14514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14515. }
  14516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14517. isKnowKey = TRUE;
  14518. }
  14519. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14520. {
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14523. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14524. {
  14525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14526. }
  14527. else
  14528. {
  14529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14530. }
  14531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14532. isKnowKey = TRUE;
  14533. }
  14534. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14535. {
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14538. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14539. {
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14541. }
  14542. else
  14543. {
  14544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14545. }
  14546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14547. isKnowKey = TRUE;
  14548. }
  14549. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14550. {
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14553. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14554. {
  14555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14556. }
  14557. else
  14558. {
  14559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14560. }
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14562. isKnowKey = TRUE;
  14563. }
  14564. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14565. {
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14568. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14569. {
  14570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14571. }
  14572. else
  14573. {
  14574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14575. }
  14576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14577. isKnowKey = TRUE;
  14578. }
  14579. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14580. {
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14583. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14584. {
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14586. }
  14587. else
  14588. {
  14589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14590. }
  14591. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14593. isKnowKey = TRUE;
  14594. }
  14595. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14596. {
  14597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14599. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14600. {
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14602. }
  14603. else
  14604. {
  14605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14606. }
  14607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14608. isKnowKey = TRUE;
  14609. }
  14610. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14611. {
  14612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14614. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14615. {
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14617. }
  14618. else
  14619. {
  14620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14621. }
  14622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14623. isKnowKey = TRUE;
  14624. }
  14625. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14626. {
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14629. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14630. {
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14632. }
  14633. else
  14634. {
  14635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14636. }
  14637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14638. isKnowKey = TRUE;
  14639. }
  14640. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14641. {
  14642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14644. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14645. {
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14647. }
  14648. else
  14649. {
  14650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14651. }
  14652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14653. isKnowKey = TRUE;
  14654. }
  14655. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14656. {
  14657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14659. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14660. {
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14662. }
  14663. else
  14664. {
  14665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14666. }
  14667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14668. isKnowKey = TRUE;
  14669. }
  14670. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14671. {
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14674. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14675. {
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14677. }
  14678. else
  14679. {
  14680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14681. }
  14682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14683. isKnowKey = TRUE;
  14684. }
  14685. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14686. {
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14689. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14690. {
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14692. }
  14693. else
  14694. {
  14695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14696. }
  14697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14698. isKnowKey = TRUE;
  14699. }
  14700. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14701. {
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14704. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14705. {
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14707. }
  14708. else
  14709. {
  14710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14711. }
  14712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14713. isKnowKey = TRUE;
  14714. }
  14715. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14716. {
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14719. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14722. }
  14723. else
  14724. {
  14725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14726. }
  14727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14728. isKnowKey = TRUE;
  14729. }
  14730. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14731. {
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14734. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14737. }
  14738. else
  14739. {
  14740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14741. }
  14742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14743. isKnowKey = TRUE;
  14744. }
  14745. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14746. {
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14749. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14750. {
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14752. }
  14753. else
  14754. {
  14755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14756. }
  14757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14758. isKnowKey = TRUE;
  14759. }
  14760. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14761. {
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14764. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14765. {
  14766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14767. }
  14768. else
  14769. {
  14770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14771. }
  14772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14773. isKnowKey = TRUE;
  14774. }
  14775. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14776. {
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14779. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14780. {
  14781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14782. }
  14783. else
  14784. {
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14786. }
  14787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14788. isKnowKey = TRUE;
  14789. }
  14790. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14791. {
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14794. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14795. {
  14796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14797. }
  14798. else
  14799. {
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14801. }
  14802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14803. isKnowKey = TRUE;
  14804. }
  14805. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14806. {
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14809. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14810. {
  14811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14812. }
  14813. else
  14814. {
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14816. }
  14817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14818. isKnowKey = TRUE;
  14819. }
  14820. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14821. {
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14824. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14825. {
  14826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14827. }
  14828. else
  14829. {
  14830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14831. }
  14832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14833. isKnowKey = TRUE;
  14834. }
  14835. /*
  14836. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14837. {
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14840. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14841. {
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14843. }
  14844. else
  14845. {
  14846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14847. }
  14848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14849. isKnowKey = TRUE;
  14850. }*/
  14851. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14852. {
  14853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14855. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14856. {
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14858. }
  14859. else
  14860. {
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14862. }
  14863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14864. isKnowKey = TRUE;
  14865. }
  14866. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14867. {
  14868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14870. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14871. {
  14872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14873. }
  14874. else
  14875. {
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14877. }
  14878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14879. isKnowKey = TRUE;
  14880. }
  14881. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14882. {
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14885. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14886. {
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14888. }
  14889. else
  14890. {
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14892. }
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14894. isKnowKey = TRUE;
  14895. }
  14896. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14897. {
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14900. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14903. }
  14904. else
  14905. {
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14907. }
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14909. isKnowKey = TRUE;
  14910. }
  14911. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14912. {
  14913. struct sysinfo s_info;
  14914. int error = sysinfo(&s_info);
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14917. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14918. {
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14920. }
  14921. else
  14922. {
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14924. }
  14925. if(error != 0)
  14926. {
  14927. DEBUG_WARN("System uptime get error: %d\n", error);
  14928. }
  14929. else
  14930. {
  14931. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14932. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14933. }
  14934. isKnowKey = TRUE;
  14935. }
  14936. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14937. {
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14939. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14940. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14941. {
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14943. }
  14944. else
  14945. {
  14946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14947. }
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14949. isKnowKey = TRUE;
  14950. }
  14951. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  14952. {
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  14954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  14955. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  14956. {
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  14958. }
  14959. else
  14960. {
  14961. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  14962. }
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14964. isKnowKey = TRUE;
  14965. }
  14966. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14967. {
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14970. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14971. {
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14973. }
  14974. else
  14975. {
  14976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14977. }
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14979. isKnowKey = TRUE;
  14980. }
  14981. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14982. {
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14985. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14988. }
  14989. else
  14990. {
  14991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14992. }
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14994. isKnowKey = TRUE;
  14995. }
  14996. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14997. {
  14998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15000. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15001. {
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15003. }
  15004. else
  15005. {
  15006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15007. }
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15009. isKnowKey = TRUE;
  15010. }
  15011. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15012. {
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15015. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15016. {
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15018. }
  15019. else
  15020. {
  15021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15022. }
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15024. isKnowKey = TRUE;
  15025. }
  15026. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15027. {
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15030. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15031. {
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15033. }
  15034. else
  15035. {
  15036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15037. }
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15039. isKnowKey = TRUE;
  15040. }
  15041. #if 1
  15042. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15043. {
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15046. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15049. }
  15050. else
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15053. }
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15055. isKnowKey = TRUE;
  15056. }
  15057. #endif
  15058. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15062. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15063. {
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15065. }
  15066. else
  15067. {
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15069. }
  15070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15071. isKnowKey = TRUE;
  15072. }
  15073. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15077. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15080. }
  15081. else
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15084. }
  15085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15086. isKnowKey = TRUE;
  15087. }
  15088. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15089. {
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15092. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15093. {
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15095. }
  15096. else
  15097. {
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15099. }
  15100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15101. isKnowKey = TRUE;
  15102. }
  15103. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15104. {
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15107. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15108. {
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15110. }
  15111. else
  15112. {
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15114. }
  15115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15116. isKnowKey = TRUE;
  15117. }
  15118. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15119. {
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15122. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15123. {
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15125. }
  15126. else
  15127. {
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15129. }
  15130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15131. isKnowKey = TRUE;
  15132. }
  15133. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15134. {
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15137. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15138. {
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15140. }
  15141. else
  15142. {
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15144. }
  15145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15146. isKnowKey = TRUE;
  15147. }
  15148. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15149. {
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15152. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15153. {
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15155. }
  15156. else
  15157. {
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15159. }
  15160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15161. isKnowKey = TRUE;
  15162. }
  15163. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15164. {
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15167. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15168. {
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15170. }
  15171. else
  15172. {
  15173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15174. }
  15175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15176. isKnowKey = TRUE;
  15177. }
  15178. //=========================================================
  15179. if(!isEmpty && !isKnowKey)
  15180. {
  15181. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15182. strcpy(unknownkey[UnknownKeynum], keyReq);
  15183. UnknownKeynum = UnknownKeynum + 1;
  15184. }
  15185. }
  15186. void processUnkownKey(void)
  15187. {
  15188. DEBUG_INFO("processUnkownKey...\n");
  15189. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15190. for(int index=0; index < UnknownKeynum; index++)
  15191. {
  15192. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15193. {
  15194. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15195. }
  15196. }
  15197. }
  15198. int setKeyValue(char *key, char *value)
  15199. {
  15200. int isSuccess = NotSupported;
  15201. int check_ascii=0;
  15202. char str[501]={0};
  15203. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15204. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15205. {
  15206. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15207. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15208. {
  15209. strcpy(str, (const char*)value);
  15210. for(int i = 0; str[i]; i++){
  15211. str[i] = tolower(str[i]);
  15212. }
  15213. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15214. isSuccess = ConfigurationStatus_Accepted;
  15215. }
  15216. else
  15217. {
  15218. isSuccess = ConfigurationStatus_Rejected;
  15219. }
  15220. }
  15221. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15222. {
  15223. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15224. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15225. {
  15226. strcpy(str, (const char*)value);
  15227. for(int i = 0; str[i]; i++){
  15228. str[i] = tolower(str[i]);
  15229. }
  15230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15231. isSuccess = ConfigurationStatus_Accepted;
  15232. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15233. }
  15234. else
  15235. {
  15236. isSuccess = ConfigurationStatus_Rejected;
  15237. }
  15238. }
  15239. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15240. {
  15241. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15242. {
  15243. strcpy(str, (const char*)value);
  15244. for(int i = 0; str[i]; i++)
  15245. {
  15246. str[i] = tolower(str[i]);
  15247. }
  15248. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15249. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15250. isSuccess = ConfigurationStatus_Accepted;
  15251. }
  15252. else
  15253. {
  15254. isSuccess = ConfigurationStatus_Rejected;
  15255. }
  15256. }
  15257. if(strcmp(key, "BlinkRepeat") == 0)
  15258. {
  15259. //Charger.BlinkRepeat = Integer.parseInt(value);
  15260. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15261. {
  15262. check_ascii = value[0];
  15263. if( (check_ascii < 48) || (check_ascii > 57) )
  15264. {
  15265. isSuccess = ConfigurationStatus_Rejected;
  15266. }
  15267. else
  15268. {
  15269. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15270. isSuccess = ConfigurationStatus_Accepted;
  15271. }
  15272. }
  15273. else
  15274. {
  15275. isSuccess = ConfigurationStatus_Rejected;
  15276. }
  15277. }
  15278. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15279. {
  15280. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15281. {
  15282. check_ascii = value[0];
  15283. if( (check_ascii < 48) || (check_ascii > 57) )
  15284. {
  15285. isSuccess = ConfigurationStatus_Rejected;
  15286. }
  15287. else
  15288. {
  15289. if((atoi(value) == 0) || (atoi(value) >= 5))
  15290. {
  15291. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15293. isSuccess = ConfigurationStatus_Accepted;
  15294. }
  15295. else
  15296. isSuccess = ConfigurationStatus_Rejected;
  15297. }
  15298. }
  15299. else
  15300. {
  15301. isSuccess = ConfigurationStatus_Rejected;
  15302. }
  15303. }
  15304. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15305. {
  15306. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15307. {
  15308. check_ascii = value[0];
  15309. if( (check_ascii < 48) || (check_ascii > 57) )
  15310. {
  15311. isSuccess = ConfigurationStatus_Rejected;
  15312. }
  15313. else
  15314. {
  15315. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15316. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15317. isSuccess = ConfigurationStatus_Accepted;
  15318. }
  15319. }
  15320. else
  15321. {
  15322. isSuccess = ConfigurationStatus_Rejected;
  15323. }
  15324. }
  15325. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15326. {
  15327. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15328. {
  15329. check_ascii = value[0];
  15330. if( (check_ascii < 48) || (check_ascii > 57) )
  15331. {
  15332. isSuccess = ConfigurationStatus_Rejected;
  15333. }
  15334. else
  15335. {
  15336. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15337. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15338. isSuccess = ConfigurationStatus_Accepted;
  15339. }
  15340. }
  15341. else
  15342. {
  15343. isSuccess = ConfigurationStatus_Rejected;
  15344. }
  15345. }
  15346. if(strcmp(key, "HeartbeatInterval") == 0)
  15347. {
  15348. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15349. {
  15350. check_ascii = value[0];
  15351. if( (check_ascii < 48) || (check_ascii > 57) )
  15352. {
  15353. isSuccess = ConfigurationStatus_Rejected;
  15354. }
  15355. else
  15356. {
  15357. if((atoi(value) == 0) || (atoi(value) >= 10))
  15358. {
  15359. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15360. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15361. HeartBeatWaitTime = atoi(value);
  15362. isSuccess = ConfigurationStatus_Accepted;
  15363. }
  15364. else
  15365. {
  15366. isSuccess = ConfigurationStatus_Rejected;
  15367. }
  15368. }
  15369. }
  15370. else
  15371. {
  15372. isSuccess = ConfigurationStatus_Rejected;
  15373. }
  15374. }
  15375. if(strcmp(key, "LightIntensity") == 0)
  15376. {
  15377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15378. {
  15379. check_ascii = value[0];
  15380. if( (check_ascii < 48) || (check_ascii > 57) )
  15381. {
  15382. isSuccess = ConfigurationStatus_Rejected;
  15383. }
  15384. else
  15385. {
  15386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15387. isSuccess = ConfigurationStatus_Accepted;
  15388. }
  15389. }
  15390. else
  15391. {
  15392. isSuccess = ConfigurationStatus_Rejected;
  15393. }
  15394. }
  15395. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15396. {
  15397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15398. {
  15399. strcpy(str, (const char*)value);
  15400. for(int i = 0; str[i]; i++)
  15401. {
  15402. str[i] = tolower(str[i]);
  15403. }
  15404. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15405. isSuccess = ConfigurationStatus_Accepted;
  15406. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15407. }
  15408. else
  15409. {
  15410. isSuccess = ConfigurationStatus_Rejected;
  15411. }
  15412. }
  15413. if(strcmp(key, "LocalPreAuthorize") == 0)
  15414. {
  15415. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15416. {
  15417. strcpy(str, (const char*)value);
  15418. for(int i = 0; str[i]; i++)
  15419. {
  15420. str[i] = tolower(str[i]);
  15421. }
  15422. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15423. isSuccess = ConfigurationStatus_Accepted;
  15424. }
  15425. else
  15426. {
  15427. isSuccess = ConfigurationStatus_Rejected;
  15428. }
  15429. }
  15430. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15431. {
  15432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15433. {
  15434. check_ascii = value[0];
  15435. if( (check_ascii < 48) || (check_ascii > 57) )
  15436. {
  15437. isSuccess = ConfigurationStatus_Rejected;
  15438. }
  15439. else
  15440. {
  15441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15442. isSuccess = ConfigurationStatus_Accepted;
  15443. }
  15444. }
  15445. else
  15446. {
  15447. isSuccess = ConfigurationStatus_Rejected;
  15448. }
  15449. }
  15450. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15451. {
  15452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15453. {
  15454. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15455. isSuccess = ConfigurationStatus_Accepted;
  15456. }
  15457. else
  15458. {
  15459. isSuccess = ConfigurationStatus_Rejected;
  15460. }
  15461. }
  15462. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15463. {
  15464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].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. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15475. isSuccess = ConfigurationStatus_Accepted;
  15476. }
  15477. }
  15478. else
  15479. {
  15480. isSuccess = ConfigurationStatus_Rejected;
  15481. }
  15482. }
  15483. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15484. {
  15485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15486. {
  15487. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15488. isSuccess = ConfigurationStatus_Accepted;
  15489. }
  15490. else
  15491. {
  15492. isSuccess = ConfigurationStatus_Rejected;
  15493. }
  15494. }
  15495. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15496. {
  15497. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15498. {
  15499. check_ascii = value[0];
  15500. if( (check_ascii < 48) || (check_ascii > 57) )
  15501. {
  15502. isSuccess = ConfigurationStatus_Rejected;
  15503. }
  15504. else
  15505. {
  15506. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15507. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15508. isSuccess = ConfigurationStatus_Accepted;
  15509. }
  15510. }
  15511. else
  15512. {
  15513. isSuccess = ConfigurationStatus_Rejected;
  15514. }
  15515. }
  15516. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15517. {
  15518. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15519. {
  15520. check_ascii = value[0];
  15521. if( (check_ascii < 48) || (check_ascii > 57) )
  15522. {
  15523. isSuccess = ConfigurationStatus_Rejected;
  15524. }
  15525. else
  15526. {
  15527. if((atoi(value) == 0) || (atoi(value) >= 3))
  15528. {
  15529. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15531. isSuccess = ConfigurationStatus_Accepted;
  15532. }
  15533. else
  15534. {
  15535. isSuccess = ConfigurationStatus_Rejected;
  15536. }
  15537. }
  15538. }
  15539. else
  15540. {
  15541. isSuccess = ConfigurationStatus_Rejected;
  15542. }
  15543. }
  15544. if(strcmp(key, "MinimumStatusDuration") == 0)
  15545. {
  15546. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15547. {
  15548. check_ascii = value[0];
  15549. if( (check_ascii < 48) || (check_ascii > 57) )
  15550. {
  15551. isSuccess = ConfigurationStatus_Rejected;
  15552. }
  15553. else
  15554. {
  15555. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15556. {
  15557. isSuccess = ConfigurationStatus_Rejected;
  15558. }
  15559. else
  15560. {
  15561. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15563. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15564. isSuccess = ConfigurationStatus_Accepted;
  15565. }
  15566. }
  15567. }
  15568. else
  15569. {
  15570. isSuccess = ConfigurationStatus_Rejected;
  15571. }
  15572. }
  15573. if(strcmp(key, "NumberOfConnectors") == 0)
  15574. {
  15575. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15576. {
  15577. check_ascii = value[0];
  15578. if( (check_ascii < 48) || (check_ascii > 57) )
  15579. {
  15580. isSuccess = ConfigurationStatus_Rejected;
  15581. }
  15582. else
  15583. {
  15584. //Charger.ResetRetries = Integer.parseInt(value);
  15585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15586. isSuccess = ConfigurationStatus_Accepted;
  15587. }
  15588. }
  15589. else
  15590. {
  15591. isSuccess = ConfigurationStatus_Rejected;
  15592. }
  15593. }
  15594. if(strcmp(key, "ResetRetries") == 0)
  15595. {
  15596. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15597. {
  15598. check_ascii = value[0];
  15599. if( (check_ascii < 48) || (check_ascii > 57) )
  15600. {
  15601. isSuccess = ConfigurationStatus_Rejected;
  15602. }
  15603. else
  15604. {
  15605. //Charger.ResetRetries = Integer.parseInt(value);
  15606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15607. isSuccess = ConfigurationStatus_Accepted;
  15608. }
  15609. }
  15610. else
  15611. {
  15612. isSuccess = ConfigurationStatus_Rejected;
  15613. }
  15614. }
  15615. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15616. {
  15617. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15618. {
  15619. strcpy(str, (const char*)value);
  15620. for(int i = 0; str[i]; i++)
  15621. {
  15622. str[i] = tolower(str[i]);
  15623. }
  15624. if(strcmp(str, "notapplicable")== 0)
  15625. {
  15626. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15627. isSuccess = ConfigurationStatus_Accepted;
  15628. }
  15629. else if(strcmp(str, "unknown")== 0)
  15630. {
  15631. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15632. isSuccess = ConfigurationStatus_Accepted;
  15633. }
  15634. else if(strcmp(str, "rst")== 0)
  15635. {
  15636. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15637. isSuccess = ConfigurationStatus_Accepted;
  15638. }
  15639. else if(strcmp(str, "rts")== 0)
  15640. {
  15641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15642. isSuccess = ConfigurationStatus_Accepted;
  15643. }
  15644. else if(strcmp(str, "srt")== 0)
  15645. {
  15646. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15647. isSuccess = ConfigurationStatus_Accepted;
  15648. }
  15649. else if(strcmp(str, "str")== 0)
  15650. {
  15651. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15652. isSuccess = ConfigurationStatus_Accepted;
  15653. }
  15654. else if(strcmp(str, "trs")== 0)
  15655. {
  15656. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15657. isSuccess = ConfigurationStatus_Accepted;
  15658. }
  15659. else if(strcmp(str, "tsr")== 0)
  15660. {
  15661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15662. isSuccess = ConfigurationStatus_Accepted;
  15663. }
  15664. else
  15665. {
  15666. isSuccess = ConfigurationStatus_Rejected;
  15667. }
  15668. }
  15669. else
  15670. {
  15671. isSuccess = ConfigurationStatus_Rejected;
  15672. }
  15673. }
  15674. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15675. {
  15676. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15677. {
  15678. check_ascii = value[0];
  15679. if( (check_ascii < 48) || (check_ascii > 57) )
  15680. {
  15681. isSuccess = ConfigurationStatus_Rejected;
  15682. }
  15683. else
  15684. {
  15685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15686. isSuccess = ConfigurationStatus_Accepted;
  15687. }
  15688. }
  15689. else
  15690. {
  15691. isSuccess = ConfigurationStatus_Rejected;
  15692. }
  15693. }
  15694. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15695. {
  15696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15697. {
  15698. strcpy(str, (const char*)value);
  15699. for(int i = 0; str[i]; i++)
  15700. {
  15701. str[i] = tolower(str[i]);
  15702. }
  15703. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15705. isSuccess = ConfigurationStatus_Accepted;
  15706. }
  15707. else
  15708. {
  15709. isSuccess = ConfigurationStatus_Rejected;
  15710. }
  15711. }
  15712. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15713. {
  15714. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15715. {
  15716. strcpy(str, (const char*)value);
  15717. for(int i = 0; str[i]; i++)
  15718. {
  15719. str[i] = tolower(str[i]);
  15720. }
  15721. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15722. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15723. isSuccess = ConfigurationStatus_Accepted;
  15724. }
  15725. else
  15726. {
  15727. isSuccess = ConfigurationStatus_Rejected;
  15728. }
  15729. }
  15730. if(strcmp(key, "StopTxnAlignedData") == 0)
  15731. {
  15732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15733. {
  15734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15735. isSuccess = ConfigurationStatus_Accepted;
  15736. }
  15737. else
  15738. {
  15739. isSuccess = ConfigurationStatus_Rejected;
  15740. }
  15741. }
  15742. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15743. {
  15744. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15745. {
  15746. check_ascii = value[0];
  15747. if( (check_ascii < 48) || (check_ascii > 57) )
  15748. {
  15749. isSuccess = ConfigurationStatus_Rejected;
  15750. }
  15751. else
  15752. {
  15753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15754. isSuccess = ConfigurationStatus_Accepted;
  15755. }
  15756. }
  15757. else
  15758. {
  15759. isSuccess = ConfigurationStatus_Rejected;
  15760. }
  15761. }
  15762. if(strcmp(key, "StopTxnSampledData") == 0)
  15763. {
  15764. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15765. {
  15766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15767. isSuccess = ConfigurationStatus_Accepted;
  15768. }
  15769. else
  15770. {
  15771. isSuccess = ConfigurationStatus_Rejected;
  15772. }
  15773. }
  15774. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15775. {
  15776. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15777. {
  15778. check_ascii = value[0];
  15779. if( (check_ascii < 48) || (check_ascii > 57) )
  15780. {
  15781. isSuccess = ConfigurationStatus_Rejected;
  15782. }
  15783. else
  15784. {
  15785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15786. isSuccess = ConfigurationStatus_Accepted;
  15787. }
  15788. }
  15789. else
  15790. {
  15791. isSuccess = ConfigurationStatus_Rejected;
  15792. }
  15793. }
  15794. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15795. {
  15796. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15797. {
  15798. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15799. isSuccess = ConfigurationStatus_Accepted;
  15800. }
  15801. else
  15802. {
  15803. isSuccess = ConfigurationStatus_Rejected;
  15804. }
  15805. }
  15806. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15807. {
  15808. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15809. {
  15810. check_ascii = value[0];
  15811. if( (check_ascii < 48) || (check_ascii > 57) )
  15812. {
  15813. isSuccess = ConfigurationStatus_Rejected;
  15814. }
  15815. else
  15816. {
  15817. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15818. isSuccess = ConfigurationStatus_Accepted;
  15819. }
  15820. }
  15821. else
  15822. {
  15823. isSuccess = ConfigurationStatus_Rejected;
  15824. }
  15825. }
  15826. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15827. {
  15828. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15829. {
  15830. check_ascii = value[0];
  15831. if( (check_ascii < 48) || (check_ascii > 57) )
  15832. {
  15833. isSuccess = ConfigurationStatus_Rejected;
  15834. }
  15835. else
  15836. {
  15837. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15839. TransactionMessageAttemptsValue = atoi(value);
  15840. isSuccess = ConfigurationStatus_Accepted;
  15841. }
  15842. }
  15843. else
  15844. {
  15845. isSuccess = ConfigurationStatus_Rejected;
  15846. }
  15847. }
  15848. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15849. {
  15850. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15851. {
  15852. check_ascii = value[0];
  15853. if( (check_ascii < 48) || (check_ascii > 57) )
  15854. {
  15855. isSuccess = ConfigurationStatus_Rejected;
  15856. }
  15857. else
  15858. {
  15859. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15860. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15861. TransactionMessageRetryIntervalValue = atoi(value);
  15862. isSuccess = ConfigurationStatus_Accepted;
  15863. }
  15864. }
  15865. else
  15866. {
  15867. isSuccess = ConfigurationStatus_Rejected;
  15868. }
  15869. }
  15870. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15871. {
  15872. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15873. {
  15874. strcpy(str, (const char*)value);
  15875. for(int i = 0; str[i]; i++)
  15876. {
  15877. str[i] = tolower(str[i]);
  15878. }
  15879. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15880. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15881. isSuccess = ConfigurationStatus_Accepted;
  15882. }
  15883. else
  15884. {
  15885. isSuccess = ConfigurationStatus_Rejected;
  15886. }
  15887. }
  15888. if(strcmp(key, "WebSocketPingInterval") == 0)
  15889. {
  15890. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15891. {
  15892. check_ascii = value[0];
  15893. if( (check_ascii < 48) || (check_ascii > 57) )
  15894. {
  15895. isSuccess = ConfigurationStatus_Rejected;
  15896. }
  15897. else
  15898. {
  15899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15900. isSuccess = ConfigurationStatus_Accepted;
  15901. if((atoi(value) == 0) || (atoi(value) >= 10))
  15902. {
  15903. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15904. isSuccess = ConfigurationStatus_Accepted;
  15905. }
  15906. else
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. else
  15911. {
  15912. isSuccess = ConfigurationStatus_Rejected;
  15913. }
  15914. }
  15915. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15916. {
  15917. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15918. {
  15919. strcpy(str, (const char*)value);
  15920. for(int i = 0; str[i]; i++)
  15921. {
  15922. str[i] = tolower(str[i]);
  15923. }
  15924. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15925. isSuccess = ConfigurationStatus_Accepted;
  15926. }
  15927. else
  15928. {
  15929. isSuccess = ConfigurationStatus_Rejected;
  15930. }
  15931. }
  15932. if(strcmp(key, "AuthorizationKey") == 0)
  15933. {
  15934. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15935. {
  15936. strcpy(str, (const char*)value);
  15937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15938. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15939. isSuccess = ConfigurationStatus_Accepted;
  15940. }
  15941. else
  15942. {
  15943. isSuccess = ConfigurationStatus_Rejected;
  15944. }
  15945. }
  15946. if(strcmp(key, "SecurityProfile") == 0)
  15947. {
  15948. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15949. {
  15950. check_ascii = value[0];
  15951. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15952. {
  15953. isSuccess = ConfigurationStatus_Rejected;
  15954. }
  15955. else if(check_ascii == 0x33)
  15956. {
  15957. isSuccess = NotSupported;
  15958. }
  15959. else
  15960. {
  15961. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15962. {
  15963. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15964. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15965. isSuccess = ConfigurationStatus_Accepted;
  15966. }
  15967. else
  15968. isSuccess = ConfigurationStatus_Rejected;
  15969. }
  15970. }
  15971. else
  15972. {
  15973. isSuccess = ConfigurationStatus_Rejected;
  15974. }
  15975. }
  15976. if(strcmp(key, "DefaultPrice") == 0)
  15977. {
  15978. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15979. {
  15980. strcpy(str, (const char*)value);
  15981. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15982. isSuccess = ConfigurationStatus_Accepted;
  15983. }
  15984. else
  15985. {
  15986. isSuccess = ConfigurationStatus_Rejected;
  15987. }
  15988. }
  15989. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15990. {
  15991. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15992. {
  15993. strcpy(str, (const char*)value);
  15994. for(int i = 0; str[i]; i++)
  15995. {
  15996. str[i] = tolower(str[i]);
  15997. }
  15998. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15999. isSuccess = ConfigurationStatus_Accepted;
  16000. }
  16001. else
  16002. {
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. }
  16006. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16007. {
  16008. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16009. {
  16010. strcpy(str, (const char*)value);
  16011. for(int i = 0; str[i]; i++)
  16012. {
  16013. str[i] = tolower(str[i]);
  16014. }
  16015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16016. isSuccess = ConfigurationStatus_Accepted;
  16017. }
  16018. else
  16019. {
  16020. isSuccess = ConfigurationStatus_Rejected;
  16021. }
  16022. }
  16023. if(strcmp(key, "SystemUptimeSec") == 0)
  16024. {
  16025. isSuccess = NotSupported;
  16026. }
  16027. if(strcmp(key, "FreeVend") == 0)
  16028. {
  16029. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16030. {
  16031. strcpy(str, (const char*)value);
  16032. for(int i = 0; str[i]; i++)
  16033. {
  16034. str[i] = tolower(str[i]);
  16035. }
  16036. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16037. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16038. isSuccess = ConfigurationStatus_Accepted;
  16039. }
  16040. else
  16041. {
  16042. isSuccess = ConfigurationStatus_Rejected;
  16043. }
  16044. }
  16045. if(strcmp(key, "FreeVendIdtag") == 0)
  16046. {
  16047. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16048. {
  16049. strcpy(str, (const char*)value);
  16050. if(strlen(str) <= 20)
  16051. {
  16052. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16053. isSuccess = ConfigurationStatus_Accepted;
  16054. }
  16055. else
  16056. {
  16057. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16058. isSuccess = ConfigurationStatus_Rejected;
  16059. }
  16060. }
  16061. else
  16062. {
  16063. isSuccess = ConfigurationStatus_Rejected;
  16064. }
  16065. }
  16066. if(strcmp(key, "OcppServer") == 0)
  16067. {
  16068. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16069. {
  16070. strcpy(str, (const char*)value);
  16071. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16072. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16073. isSuccess = ConfigurationStatus_Accepted;
  16074. }
  16075. else
  16076. {
  16077. isSuccess = ConfigurationStatus_Rejected;
  16078. }
  16079. }
  16080. if(strcmp(key, "MaintainServer") == 0)
  16081. {
  16082. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16083. {
  16084. strcpy(str, (const char*)value);
  16085. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16086. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16087. isSuccess = ConfigurationStatus_Accepted;
  16088. }
  16089. else
  16090. {
  16091. isSuccess = ConfigurationStatus_Rejected;
  16092. }
  16093. }
  16094. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16095. {
  16096. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16097. {
  16098. strcpy(str, (const char*)value);
  16099. for(int i = 0; str[i]; i++)
  16100. {
  16101. str[i] = tolower(str[i]);
  16102. }
  16103. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16104. isSuccess = ConfigurationStatus_Accepted;
  16105. }
  16106. else
  16107. {
  16108. isSuccess = ConfigurationStatus_Rejected;
  16109. }
  16110. }
  16111. if(strcmp(key, "StatusNotificationInterval") == 0)
  16112. {
  16113. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16114. {
  16115. check_ascii = value[0];
  16116. if( (check_ascii < 48) || (check_ascii > 57) )
  16117. {
  16118. isSuccess = ConfigurationStatus_Rejected;
  16119. }
  16120. else
  16121. {
  16122. if((atoi(value) == 0) || (atoi(value) >= 10))
  16123. {
  16124. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16125. isSuccess = ConfigurationStatus_Accepted;
  16126. }
  16127. else
  16128. isSuccess = ConfigurationStatus_Rejected;
  16129. }
  16130. }
  16131. else
  16132. {
  16133. isSuccess = ConfigurationStatus_Rejected;
  16134. }
  16135. }
  16136. #if 0
  16137. //For OCPP Test Case
  16138. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16139. {
  16140. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16141. {
  16142. strcpy(str, (const char*)value);
  16143. for(int i = 0; str[i]; i++)
  16144. {
  16145. str[i] = tolower(str[i]);
  16146. }
  16147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16148. isSuccess = ConfigurationStatus_Accepted;
  16149. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16150. }
  16151. else
  16152. {
  16153. isSuccess = ConfigurationStatus_Rejected;
  16154. }
  16155. }
  16156. #endif
  16157. #if 1
  16158. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16159. {
  16160. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16161. {
  16162. strcpy(str, (const char*)value);
  16163. for(int i = 0; str[i]; i++)
  16164. {
  16165. str[i] = tolower(str[i]);
  16166. }
  16167. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16168. isSuccess = ConfigurationStatus_Accepted;
  16169. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16170. }
  16171. else
  16172. {
  16173. isSuccess = ConfigurationStatus_Rejected;
  16174. }
  16175. }
  16176. #endif
  16177. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16178. {
  16179. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16180. {
  16181. check_ascii = value[0];
  16182. if( (check_ascii < 48) || (check_ascii > 57) )
  16183. {
  16184. isSuccess = ConfigurationStatus_Rejected;
  16185. }
  16186. else
  16187. {
  16188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16189. isSuccess = ConfigurationStatus_Accepted;
  16190. }
  16191. }
  16192. else
  16193. {
  16194. isSuccess = ConfigurationStatus_Rejected;
  16195. }
  16196. }
  16197. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16198. {
  16199. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16200. {
  16201. check_ascii = value[0];
  16202. if( (check_ascii < 48) || (check_ascii > 57) )
  16203. {
  16204. isSuccess = ConfigurationStatus_Rejected;
  16205. }
  16206. else
  16207. {
  16208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16209. isSuccess = ConfigurationStatus_Accepted;
  16210. }
  16211. }
  16212. else
  16213. {
  16214. isSuccess = ConfigurationStatus_Rejected;
  16215. }
  16216. }
  16217. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16218. {
  16219. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16220. {
  16221. strcpy(str, (const char*)value);
  16222. for(int i = 0; str[i]; i++)
  16223. {
  16224. str[i] = tolower(str[i]);
  16225. }
  16226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16227. isSuccess = ConfigurationStatus_Accepted;
  16228. }
  16229. else
  16230. {
  16231. isSuccess = ConfigurationStatus_Rejected;
  16232. }
  16233. }
  16234. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16235. {
  16236. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16237. {
  16238. check_ascii = value[0];
  16239. if( (check_ascii < 48) || (check_ascii > 57) )
  16240. {
  16241. isSuccess = ConfigurationStatus_Rejected;
  16242. }
  16243. else
  16244. {
  16245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16246. isSuccess = ConfigurationStatus_Accepted;
  16247. }
  16248. }
  16249. else
  16250. {
  16251. isSuccess = ConfigurationStatus_Rejected;
  16252. }
  16253. }
  16254. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16255. {
  16256. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16257. {
  16258. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16259. isSuccess = ConfigurationStatus_Accepted;
  16260. }
  16261. else
  16262. {
  16263. isSuccess = ConfigurationStatus_Rejected;
  16264. }
  16265. }
  16266. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16267. {
  16268. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16269. {
  16270. check_ascii = value[0];
  16271. if( (check_ascii < 48) || (check_ascii > 57) )
  16272. {
  16273. isSuccess = ConfigurationStatus_Rejected;
  16274. }
  16275. else
  16276. {
  16277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16278. isSuccess = ConfigurationStatus_Accepted;
  16279. }
  16280. }
  16281. else
  16282. {
  16283. isSuccess = ConfigurationStatus_Rejected;
  16284. }
  16285. }
  16286. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16287. {
  16288. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16289. {
  16290. strcpy(str, (const char*)value);
  16291. for(int i = 0; str[i]; i++)
  16292. {
  16293. str[i] = tolower(str[i]);
  16294. }
  16295. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16296. isSuccess = ConfigurationStatus_Accepted;
  16297. }
  16298. else
  16299. {
  16300. isSuccess = ConfigurationStatus_Rejected;
  16301. }
  16302. }
  16303. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16304. {
  16305. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16306. {
  16307. check_ascii = value[0];
  16308. if( (check_ascii < 48) || (check_ascii > 57) )
  16309. {
  16310. isSuccess = ConfigurationStatus_Rejected;
  16311. }
  16312. else
  16313. {
  16314. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16315. isSuccess = ConfigurationStatus_Accepted;
  16316. }
  16317. }
  16318. else
  16319. {
  16320. isSuccess = ConfigurationStatus_Rejected;
  16321. }
  16322. }
  16323. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16324. return isSuccess;
  16325. }
  16326. int TransactionMessageAttemptsGet(void)
  16327. {
  16328. return TransactionMessageAttemptsValue;
  16329. }
  16330. int FirstHeartBeatResponse(void)
  16331. {
  16332. return FirstHeartBeat;
  16333. }
  16334. int TransactionMessageRetryIntervalGet(void)
  16335. {
  16336. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16337. }
  16338. int ReadHttpStatus(int sock)
  16339. {
  16340. //char c;
  16341. char buff[1024]="",*ptr=buff+1;
  16342. int bytes_received, status;
  16343. DEBUG_INFO("Begin Response ..\n");
  16344. while((bytes_received = recv(sock, ptr, 1, 0))){
  16345. if(bytes_received==-1){
  16346. perror("ReadHttpStatus");
  16347. exit(1);
  16348. }
  16349. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16350. ptr++;
  16351. }
  16352. *ptr=0;
  16353. ptr=buff+1;
  16354. sscanf(ptr,"%*s %d ", &status);
  16355. DEBUG_INFO("%s\n",ptr);
  16356. DEBUG_INFO("status=%d\n",status);
  16357. DEBUG_INFO("End Response ..\n");
  16358. return (bytes_received>0)?status:0;
  16359. }
  16360. //the only filed that it parsed is 'Content-Length'
  16361. int ParseHeader(int sock)
  16362. {
  16363. //char c;
  16364. char buff[1024]="",*ptr=buff+4;
  16365. int bytes_received;
  16366. DEBUG_INFO("Begin HEADER ..\n");
  16367. while((bytes_received = recv(sock, ptr, 1, 0))){
  16368. if(bytes_received==-1){
  16369. perror("Parse Header");
  16370. exit(1);
  16371. }
  16372. if(
  16373. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16374. (ptr[-1]=='\r') && (*ptr=='\n' )
  16375. ) break;
  16376. ptr++;
  16377. }
  16378. *ptr=0;
  16379. ptr=buff+4;
  16380. //printf("%s",ptr);
  16381. if(bytes_received){
  16382. ptr=strstr(ptr,"Content-Length:");
  16383. if(ptr){
  16384. sscanf(ptr,"%*s %d",&bytes_received);
  16385. }else
  16386. bytes_received=-1; //unknown size
  16387. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16388. }
  16389. DEBUG_INFO("End HEADER ..\n");
  16390. return bytes_received ;
  16391. }
  16392. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16393. {
  16394. int result = TRUE;
  16395. char rmFileCmd[100]={0};
  16396. char FilePath[100]={0};
  16397. char ftpbuf[200];
  16398. int systemresult;
  16399. sprintf(FilePath,"/mnt/%s",filename);
  16400. system("ping 8.8.8.8 &");
  16401. if((access(FilePath,F_OK))!=-1)
  16402. {
  16403. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16404. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16405. system(rmFileCmd);
  16406. }
  16407. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16408. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16409. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16410. systemresult = system(ftpbuf);
  16411. if(systemresult != 0)
  16412. {
  16413. DEBUG_INFO("http DownLoad error!\n");
  16414. result = FALSE;
  16415. }
  16416. system("pkill ping");
  16417. return result;
  16418. }
  16419. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16420. {
  16421. int result = TRUE;
  16422. char rmFileCmd[100]={0};
  16423. char FilePath[100]={0};
  16424. char ftpbuf[200];
  16425. int systemresult;
  16426. sprintf(FilePath,"/mnt/%s",filename);
  16427. system("ping 8.8.8.8 &");
  16428. if((access(FilePath,F_OK))!=-1)
  16429. {
  16430. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16431. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16432. system(rmFileCmd);
  16433. }
  16434. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16435. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16436. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16437. systemresult = system(ftpbuf);
  16438. if(systemresult != 0)
  16439. {
  16440. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16441. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16442. systemresult = system(ftpbuf);
  16443. if(systemresult != 0)
  16444. {
  16445. DEBUG_WARN("wget error!\n");
  16446. result = FALSE;
  16447. }
  16448. }
  16449. system("pkill ping");
  16450. return result;
  16451. }
  16452. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16453. {
  16454. char rmFileCmd[100]={0};
  16455. char FilePath[100]={0};
  16456. char buf[512];
  16457. int systemresult = 0;
  16458. //DEBUG_INFO("filename=%s\n",filename);
  16459. //DEBUG_INFO("url=%s\n",url);
  16460. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16461. if((access(FilePath,F_OK))!=-1)
  16462. {
  16463. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16464. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16465. system(rmFileCmd);
  16466. }
  16467. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16468. if(fp == NULL)
  16469. {
  16470. DEBUG_INFO("log is NULL\n");
  16471. return FALSE;
  16472. }
  16473. else
  16474. {
  16475. fprintf(fp, "%s\n", url);
  16476. fprintf(fp, "%s\n", filename);
  16477. fclose(fp);
  16478. }
  16479. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16480. if(phpFP == NULL)
  16481. {
  16482. DEBUG_INFO("PHP upload fail.\n");
  16483. return FALSE;
  16484. }
  16485. else
  16486. {
  16487. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16488. {
  16489. if(strstr(buf, "result") != NULL)
  16490. {
  16491. sscanf(buf, "result: %d", &systemresult);
  16492. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16493. }
  16494. }
  16495. pclose(phpFP);
  16496. }
  16497. if(systemresult != 1)
  16498. {
  16499. DEBUG_INFO("HTTP upload error!\n");
  16500. return FALSE;
  16501. }
  16502. return TRUE;
  16503. }
  16504. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16505. {
  16506. int result = FALSE;
  16507. char ftpbuf[200];
  16508. int systemresult;
  16509. /*
  16510. // Domaind name transfer to IP address
  16511. struct hostent* server;
  16512. char *IPbuffer;
  16513. server = gethostbyname(location);
  16514. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16515. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16516. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16517. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16518. systemresult = system(ftpbuf);
  16519. if(systemresult != 0)
  16520. {
  16521. DEBUG_INFO("ftpput error!\n");
  16522. }
  16523. else
  16524. {
  16525. result = TRUE;
  16526. DEBUG_INFO("ftpput OK!\n");
  16527. }
  16528. return result;
  16529. }
  16530. int GetOcppServerURL()
  16531. {
  16532. int result = FALSE;
  16533. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16534. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16535. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16536. struct yuarel url;
  16537. char urlStr[512];
  16538. // OCPPPH only
  16539. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16540. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16541. {
  16542. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16543. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16544. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16545. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16546. if(yuarel_parse(&url, urlStr) != -1)
  16547. {
  16548. sprintf(OcppProtocol, "%s", url.scheme);
  16549. sprintf(OcppHost, "%s", url.host);
  16550. if(url.path == NULL)
  16551. OcppTempPath[0] = '\0';
  16552. else
  16553. sprintf(OcppTempPath, "%s", url.path);
  16554. if(url.port == 0)
  16555. {
  16556. if(strcmp(OcppProtocol, "wss") == 0)
  16557. OcppPort = 443;
  16558. else
  16559. OcppPort = 80;
  16560. }
  16561. else
  16562. OcppPort = url.port;
  16563. result = TRUE;
  16564. }
  16565. }
  16566. else
  16567. {
  16568. strcpy(OcppHost,"");
  16569. }
  16570. return result;
  16571. }
  16572. int GetOcppPath()
  16573. {
  16574. int result = FALSE;
  16575. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16576. {
  16577. if(OcppTempPath == NULL)
  16578. {
  16579. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16580. }
  16581. else
  16582. {
  16583. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16584. }
  16585. result = TRUE;
  16586. goto End;
  16587. }
  16588. else
  16589. {
  16590. strcpy(OcppPath,"");
  16591. }
  16592. End:
  16593. return result;
  16594. }
  16595. int GetOcppPort()
  16596. {
  16597. return OcppPort;
  16598. }
  16599. int GetOcppConnStatus(void)
  16600. {
  16601. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16602. }
  16603. void SetOcppConnStatus(uint8_t status)
  16604. {
  16605. ShmOCPP16DataPH->OcppConnStatus = status;
  16606. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16607. }
  16608. int GetHeartBeatWithNOResponse(void)
  16609. {
  16610. return HeartBeatWithNOResponse;
  16611. }
  16612. void SetHeartBeatWithNOResponse(void)
  16613. {
  16614. HeartBeatWithNOResponse = 0;
  16615. }
  16616. void GetStartTransactionIdTag(int gun_index)
  16617. {
  16618. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16619. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16620. }
  16621. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16622. {
  16623. char ch;
  16624. FILE *fptr1;
  16625. int temptransactionId;
  16626. char str[100]={0};
  16627. temptransactionId = 0;
  16628. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16629. {
  16630. DEBUG_INFO("IdTag is empty.\n");
  16631. return temptransactionId;
  16632. }
  16633. /*------ Read the file ----------------*/
  16634. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16635. if (!fptr1)
  16636. {
  16637. DEBUG_INFO("QueueTransactionId file open error.\n");
  16638. //printf(" File not found or unable to open the input file!!\n");
  16639. return temptransactionId;
  16640. }
  16641. ch=fgetc(fptr1);
  16642. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16643. rewind(fptr1);
  16644. if(ch!=EOF)
  16645. {
  16646. // printf("%c",ch);
  16647. while (fgets(str, 100, fptr1) != NULL)
  16648. {
  16649. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16650. if(str[0]=='\0')
  16651. {
  16652. break;
  16653. }
  16654. char *revbuf[8] = {0}; // Variable store string split
  16655. int num = 0;// Quantity after string split
  16656. DEBUG_INFO("Transaction queue data= %s\n", str);
  16657. splitstring(str,",",revbuf,&num); // String split
  16658. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16659. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16660. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16661. DEBUG_INFO("------------------------------\n");
  16662. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16663. {
  16664. if(isStopTransaction)
  16665. {
  16666. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16667. {
  16668. temptransactionId = atoi(revbuf[2]);
  16669. //break;
  16670. }
  16671. }
  16672. else
  16673. {
  16674. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16675. {
  16676. temptransactionId = atoi(revbuf[2]);
  16677. //break;
  16678. }
  16679. }
  16680. }
  16681. }
  16682. }
  16683. else
  16684. DEBUG_INFO("EOF\n");
  16685. fclose(fptr1);
  16686. /*------- End of reading ---------------*/
  16687. return temptransactionId;
  16688. }
  16689. void SetTransactionIdZero(int transactionId)
  16690. {
  16691. char ch;
  16692. FILE *fptr1, *fptr2;
  16693. int temptransactionId = 0;
  16694. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16695. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16696. if (!fptr1)
  16697. {
  16698. //printf(" File not found or unable to open the input file!!\n");
  16699. return ;
  16700. }
  16701. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16702. if (!fptr2)
  16703. {
  16704. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16705. fclose(fptr1);
  16706. return ;
  16707. }
  16708. ch=fgetc(fptr1);
  16709. rewind(fptr1);
  16710. if(ch!=EOF)
  16711. {
  16712. // copy all contents to the temporary file except the specific line
  16713. while (fgets(str, 100, fptr1) != NULL)
  16714. {
  16715. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16716. if(str[0]=='\0')
  16717. {
  16718. break;
  16719. }
  16720. char *revbuf[8] = {0};
  16721. int num = 0;
  16722. strcpy(strtemp, str);
  16723. splitstring(str,",",revbuf,&num);
  16724. if(revbuf[2][0] != '\0')
  16725. {
  16726. temptransactionId = atoi(revbuf[2]);
  16727. if(transactionId != temptransactionId)
  16728. {
  16729. fprintf(fptr2, "%s\n", strtemp);
  16730. }
  16731. }
  16732. }
  16733. }
  16734. fclose(fptr1);
  16735. fclose(fptr2);
  16736. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16737. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16738. /*------ Read the file ----------------*/
  16739. }
  16740. int InternetDisconnect(void)
  16741. {
  16742. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16743. }
  16744. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16745. void storeTempStopTransaction(int gun_index)
  16746. {
  16747. char guid[37]={0};
  16748. int tempIndex = 0;
  16749. char TempStopTransaction[256];
  16750. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16751. DEBUG_INFO("storeTempStopTransaction...\n");
  16752. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16753. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16754. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16755. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16756. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16757. {
  16758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16759. {
  16760. tempIndex = ((gun_index==2) ? 1: 0);
  16761. }
  16762. else
  16763. {
  16764. tempIndex = gun_index;
  16765. }
  16766. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16767. {
  16768. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16769. {
  16770. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16771. }
  16772. }// END OF CHAdeMO_QUANTITY
  16773. }
  16774. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16775. {
  16776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16777. {
  16778. tempIndex = ((gun_index==2) ? 1: 0);
  16779. }
  16780. else
  16781. {
  16782. tempIndex = gun_index;
  16783. }
  16784. for (int index = 0; index < CCS_QUANTITY; index++)
  16785. {
  16786. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16787. {
  16788. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16789. }
  16790. }// END OF CCS_QUANTITY
  16791. }
  16792. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16793. {
  16794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16795. {
  16796. tempIndex = ((gun_index==2) ? 1: 0);
  16797. }
  16798. else
  16799. {
  16800. tempIndex = gun_index;
  16801. }
  16802. for (int index = 0; index < GB_QUANTITY; index++)
  16803. {
  16804. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16805. {
  16806. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16807. }
  16808. }// END OF GB_QUANTITY
  16809. }
  16810. else if(gunType[gun_index] == GUN_TYPE_DO)
  16811. {
  16812. tempIndex = gun_index;
  16813. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16814. {
  16815. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16816. {
  16817. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16818. }
  16819. }
  16820. }
  16821. else
  16822. {
  16823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16824. {
  16825. tempIndex = 2;
  16826. }
  16827. else
  16828. {
  16829. tempIndex = gun_index;
  16830. }
  16831. for (int index = 0; index < AC_QUANTITY; index++)
  16832. {
  16833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16834. {
  16835. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16836. }
  16837. }// END OF AC_QUANTITY
  16838. }
  16839. //Stop Transaction Time
  16840. struct timeval tmnow;
  16841. struct tm *tm;
  16842. char buf[28];//, usec_buf[6];
  16843. gettimeofday(&tmnow, NULL);
  16844. time_t t;
  16845. t = time(NULL);
  16846. /*UTC time and date*/
  16847. tm = gmtime(&t);
  16848. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16849. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16850. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16852. random_uuid(guid);
  16853. /***********************************transactionData******************************************************/
  16854. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16855. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16856. //=================================
  16857. //1. Transaction_Begin
  16858. //=================================
  16859. //============================== Energy.Active.Import.Interval ===========================================
  16860. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16861. {
  16862. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16865. 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*/]);
  16866. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16867. 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))
  16868. {
  16869. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16870. }
  16871. else
  16872. {
  16873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16874. }
  16875. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16876. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16877. }
  16878. //=================================
  16879. //2. Transaction_End
  16880. //=================================
  16881. //2.1====================================== Current.Import L1 ==============================================
  16882. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16883. {
  16884. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16885. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16886. {
  16887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16888. {
  16889. tempIndex = ((gun_index==2) ? 1: 0);
  16890. }
  16891. else
  16892. {
  16893. tempIndex = gun_index;
  16894. }
  16895. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16896. {
  16897. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16898. {
  16899. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16900. }
  16901. }// End of for CHAdeMO_QUANTITY
  16902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16903. }
  16904. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16905. {
  16906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16907. {
  16908. tempIndex = ((gun_index==2) ? 1: 0);
  16909. }
  16910. else
  16911. {
  16912. tempIndex = gun_index;
  16913. }
  16914. for (int index = 0; index < CCS_QUANTITY; index++)
  16915. {
  16916. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16917. {
  16918. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16919. }
  16920. }// End of for CCS_QUANTITY
  16921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16922. }
  16923. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16924. {
  16925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16926. {
  16927. tempIndex = ((gun_index==2) ? 1: 0);
  16928. }
  16929. else
  16930. {
  16931. tempIndex = gun_index;
  16932. }
  16933. for (int index = 0; index < GB_QUANTITY; index++)
  16934. {
  16935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16936. {
  16937. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16938. }
  16939. }// End of for GB_QUANTITY
  16940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16941. }
  16942. else if(gunType[gun_index] == GUN_TYPE_DO)
  16943. {
  16944. tempIndex = gun_index;
  16945. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16946. {
  16947. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16948. {
  16949. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16950. }
  16951. }
  16952. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  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. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16969. }
  16970. }// End of for AC_QUANTITY
  16971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16972. }
  16973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16976. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16977. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16979. }
  16980. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16981. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16982. {
  16983. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16984. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16985. {
  16986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16987. {
  16988. tempIndex = ((gun_index==2) ? 1: 0);
  16989. }
  16990. else
  16991. {
  16992. tempIndex = gun_index;
  16993. }
  16994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16995. {
  16996. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16997. {
  16998. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16999. }
  17000. }// END OF CHAdeMO_QUANTITY
  17001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17002. }
  17003. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17004. {
  17005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17006. {
  17007. tempIndex = ((gun_index==2) ? 1: 0);
  17008. }
  17009. else
  17010. {
  17011. tempIndex = gun_index;
  17012. }
  17013. for (int index = 0; index < CCS_QUANTITY; index++)
  17014. {
  17015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17016. {
  17017. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17018. }
  17019. }// END OF CCS_QUANTITY
  17020. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17021. }
  17022. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17023. {
  17024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17025. {
  17026. tempIndex = ((gun_index==2) ? 1: 0);
  17027. }
  17028. else
  17029. {
  17030. tempIndex = gun_index;
  17031. }
  17032. for (int index = 0; index < GB_QUANTITY; index++)
  17033. {
  17034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17035. {
  17036. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17037. }
  17038. }// END OF GB_QUANTITY
  17039. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17040. }
  17041. else if(gunType[gun_index] == GUN_TYPE_DO)
  17042. {
  17043. tempIndex = gun_index;
  17044. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17045. {
  17046. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17047. {
  17048. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17049. }
  17050. }
  17051. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17052. }
  17053. else
  17054. {
  17055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17056. {
  17057. tempIndex = 2;
  17058. }
  17059. else
  17060. {
  17061. tempIndex = gun_index;
  17062. }
  17063. for (int index = 0; index < AC_QUANTITY; index++)
  17064. {
  17065. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17066. {
  17067. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17068. }
  17069. }// END OF AC_QUANTITY
  17070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17071. }
  17072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17075. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17078. }
  17079. //2.3====================================== Power.Active.Import =========================================
  17080. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17081. {
  17082. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17083. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17084. {
  17085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17086. {
  17087. tempIndex = ((gun_index==2) ? 1: 0);
  17088. }
  17089. else
  17090. {
  17091. tempIndex = gun_index;
  17092. }
  17093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17094. {
  17095. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17096. {
  17097. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17098. }
  17099. } // End for CHAdeMO_QUANTITY
  17100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17101. }
  17102. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17103. {
  17104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17105. {
  17106. tempIndex = ((gun_index==2) ? 1: 0);
  17107. }
  17108. else
  17109. {
  17110. tempIndex = gun_index;
  17111. }
  17112. for (int index = 0; index < CCS_QUANTITY; index++)
  17113. {
  17114. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17115. {
  17116. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17117. }
  17118. } // END for CCS_QUANTITY
  17119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17120. }
  17121. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17122. {
  17123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17124. {
  17125. tempIndex = ((gun_index==2) ? 1: 0);
  17126. }
  17127. else
  17128. {
  17129. tempIndex = gun_index;
  17130. }
  17131. for (int index = 0; index < GB_QUANTITY; index++)
  17132. {
  17133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17134. {
  17135. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17136. }
  17137. }// END for GB_QUANTITY
  17138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17139. }
  17140. else if(gunType[gun_index] == GUN_TYPE_DO)
  17141. {
  17142. tempIndex = gun_index;
  17143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17144. {
  17145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17146. {
  17147. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17148. }
  17149. }
  17150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17151. }
  17152. else
  17153. {
  17154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17155. {
  17156. tempIndex = 2;
  17157. }
  17158. else
  17159. {
  17160. tempIndex = gun_index;
  17161. }
  17162. for (int index = 0; index < AC_QUANTITY; index++)
  17163. {
  17164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17165. {
  17166. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17167. }
  17168. } // END for AC_QUANTITY
  17169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17170. }
  17171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17174. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17177. }
  17178. //2.4====================================== Voltage L1 ====================================================
  17179. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17180. {
  17181. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17182. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17183. {
  17184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17185. {
  17186. tempIndex = ((gun_index==2) ? 1: 0);
  17187. }
  17188. else
  17189. {
  17190. tempIndex = gun_index;
  17191. }
  17192. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17193. {
  17194. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17195. {
  17196. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17197. }
  17198. } // END OF FOR CHAdeMO_QUANTITY
  17199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17200. }
  17201. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17202. {
  17203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17204. {
  17205. tempIndex = ((gun_index==2) ? 1: 0);
  17206. }
  17207. else
  17208. {
  17209. tempIndex = gun_index;
  17210. }
  17211. for (int index = 0; index < CCS_QUANTITY; index++)
  17212. {
  17213. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17214. {
  17215. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17216. }
  17217. } // END OF FOR CCS_QUANTITY
  17218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17219. }
  17220. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17221. {
  17222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17223. {
  17224. tempIndex = ((gun_index==2) ? 1: 0);
  17225. }
  17226. else
  17227. {
  17228. tempIndex = gun_index;
  17229. }
  17230. for (int index = 0; index < GB_QUANTITY; index++)
  17231. {
  17232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17233. {
  17234. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17235. }
  17236. } // END OF FOR GB_QUANTITY
  17237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17238. }
  17239. else if(gunType[gun_index] == GUN_TYPE_DO)
  17240. {
  17241. tempIndex = gun_index;
  17242. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17243. {
  17244. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17245. {
  17246. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17247. }
  17248. }
  17249. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17250. }
  17251. else
  17252. {
  17253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17254. {
  17255. tempIndex = 2;
  17256. }
  17257. else
  17258. {
  17259. tempIndex = gun_index;
  17260. }
  17261. for (int index = 0; index < AC_QUANTITY; index++)
  17262. {
  17263. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17264. {
  17265. 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
  17266. }
  17267. } // END OF FOR AC_QUANTITY
  17268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17269. }
  17270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17273. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17276. }
  17277. //2.5============================================== End SoC =========================================================
  17278. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17279. {
  17280. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17281. 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))
  17282. {
  17283. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17284. {
  17285. tempIndex = ((gun_index==2) ? 1: 0);
  17286. }
  17287. else
  17288. {
  17289. tempIndex = gun_index;
  17290. }
  17291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17292. {
  17293. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17294. {
  17295. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17296. {
  17297. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17298. }
  17299. }
  17300. }
  17301. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17302. {
  17303. for (int index = 0; index < CCS_QUANTITY; index++)
  17304. {
  17305. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17306. {
  17307. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17308. }
  17309. }
  17310. }
  17311. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17312. {
  17313. for (int index = 0; index < GB_QUANTITY; index++)
  17314. {
  17315. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17316. {
  17317. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17318. }
  17319. }
  17320. }
  17321. else if(gunType[gun_index] == GUN_TYPE_DO)
  17322. {
  17323. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17324. {
  17325. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17326. {
  17327. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17328. }
  17329. }
  17330. }
  17331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17333. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17337. } // END FOR DC CASE
  17338. }
  17339. //2.6====================================== Current.Import L2 ==============================================
  17340. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17341. {
  17342. // AC 3 phase L2 current
  17343. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17344. {
  17345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17346. {
  17347. tempIndex = 2;
  17348. }
  17349. else
  17350. {
  17351. tempIndex = gun_index;
  17352. }
  17353. for (int index = 0; index < AC_QUANTITY; index++)
  17354. {
  17355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17356. {
  17357. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17358. }
  17359. }// End of for AC_QUANTITY
  17360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17361. }
  17362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17367. }
  17368. //2.7====================================== Current.Import L3 ==============================================
  17369. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17370. {
  17371. // AC 3 phase L3 current
  17372. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17373. {
  17374. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17375. {
  17376. tempIndex = 2;
  17377. }
  17378. else
  17379. {
  17380. tempIndex = gun_index;
  17381. }
  17382. for (int index = 0; index < AC_QUANTITY; index++)
  17383. {
  17384. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17385. {
  17386. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17387. }
  17388. }// End of for AC_QUANTITY
  17389. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17390. }
  17391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17393. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17394. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17395. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17396. }
  17397. //2.9====================================== Voltage L2 ====================================================
  17398. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17399. {
  17400. // AC 3 phase L2 volatge
  17401. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17402. {
  17403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17404. {
  17405. tempIndex = 2;
  17406. }
  17407. else
  17408. {
  17409. tempIndex = gun_index;
  17410. }
  17411. for (int index = 0; index < AC_QUANTITY; index++)
  17412. {
  17413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17414. {
  17415. 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
  17416. }
  17417. } // END OF FOR AC_QUANTITY
  17418. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17419. }
  17420. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17421. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17422. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17423. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17424. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17425. }
  17426. //2.10====================================== Voltage L3 ====================================================
  17427. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17428. {
  17429. // AC 3 phase L3 volatge
  17430. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17431. {
  17432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17433. {
  17434. tempIndex = 2;
  17435. }
  17436. else
  17437. {
  17438. tempIndex = gun_index;
  17439. }
  17440. for (int index = 0; index < AC_QUANTITY; index++)
  17441. {
  17442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17443. {
  17444. 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
  17445. }
  17446. } // END OF FOR AC_QUANTITY
  17447. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17448. }
  17449. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17451. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17454. }
  17455. //====================== Start SoC ================================
  17456. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17457. {
  17458. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17459. 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))
  17460. {
  17461. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17462. {
  17463. tempIndex = ((gun_index==2) ? 1: 0);
  17464. }
  17465. else
  17466. {
  17467. tempIndex = gun_index;
  17468. }
  17469. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17470. {
  17471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17472. {
  17473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17474. {
  17475. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17476. }
  17477. }
  17478. }
  17479. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17480. {
  17481. for (int index = 0; index < CCS_QUANTITY; index++)
  17482. {
  17483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17484. {
  17485. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17486. }
  17487. }
  17488. }
  17489. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17490. {
  17491. for (int index = 0; index < GB_QUANTITY; index++)
  17492. {
  17493. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17494. {
  17495. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17496. }
  17497. }
  17498. }
  17499. else if(gunType[gun_index] == GUN_TYPE_DO)
  17500. {
  17501. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17502. {
  17503. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17504. {
  17505. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17506. }
  17507. }
  17508. }
  17509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17511. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17512. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17513. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17515. } // END FOR DC CASE
  17516. }
  17517. //======================================== Message create ==============================================
  17518. json_object *StopTransaction = json_object_new_object();
  17519. json_object *transactionDatas = json_object_new_array();
  17520. json_object *sampledValues = json_object_new_array();
  17521. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17522. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17523. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17524. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17525. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17526. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17527. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17528. {
  17529. json_object *transactionData = json_object_new_object();
  17530. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17531. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17532. {
  17533. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17534. {
  17535. json_object *sampledValue = json_object_new_object();
  17536. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17537. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17538. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17539. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17540. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17541. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17542. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17543. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17544. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17545. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17546. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17547. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17548. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17549. json_object_array_add(sampledValues, sampledValue);
  17550. }
  17551. }
  17552. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17553. json_object_array_add(transactionDatas, transactionData);
  17554. }
  17555. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17556. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17557. ,MESSAGE_TYPE_CALL
  17558. ,guid
  17559. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17560. json_object_put(StopTransaction);
  17561. // Check File "TempStopTransaction" Exist
  17562. if((access(TempStopTransaction,F_OK))!=-1)
  17563. {
  17564. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17565. fclose(fopen(TempStopTransaction, "w"));
  17566. }
  17567. else
  17568. {
  17569. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17570. FILE *log = fopen(TempStopTransaction, "w+");
  17571. if(log == NULL)
  17572. {
  17573. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17574. return ;
  17575. }
  17576. else
  17577. {
  17578. fclose(log);
  17579. }
  17580. }
  17581. //Add TempStopTransaction | Update TempStopTransaction
  17582. // open file for writing
  17583. FILE *outfile;
  17584. outfile = fopen (TempStopTransaction, "a");
  17585. //DEBUG_INFO("data = %s\n", queuedata);
  17586. fputs(queuedata, outfile);
  17587. fputs("\n", outfile);
  17588. fclose (outfile);
  17589. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17590. }
  17591. void checkTempStopTransaction(int gun_index)
  17592. {
  17593. FILE *fptr1;
  17594. char ch;
  17595. char str[QUEUE_MESSAGE_LENGTH]={0};
  17596. char guid[37]={0};
  17597. char tempdata[65]={0};
  17598. char connectorStr[2]={0};
  17599. char TempStopTransaction[256];
  17600. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17601. fptr1 = fopen(TempStopTransaction, "r");
  17602. //TempStopTransaction格式: 槍號,StopTransaction封包
  17603. if (!fptr1)
  17604. {
  17605. //printf(" File not found or unable to open the input file!!\n");
  17606. return ;
  17607. }
  17608. ch=fgetc(fptr1);
  17609. //printf(" Now the content of the file %s is : \n",fname);
  17610. rewind(fptr1);
  17611. if(ch!=EOF)
  17612. {
  17613. // copy all contents to the temporary file except the specific line
  17614. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17615. {
  17616. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17617. if(str[0]=='\0')
  17618. {
  17619. break;
  17620. }
  17621. //TempStopTransaction格式: 槍號,StopTransaction封包
  17622. strncpy(connectorStr, str, 1);
  17623. if(atoi(connectorStr) != (gun_index+1))
  17624. {
  17625. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17626. fclose(fptr1);
  17627. return ;
  17628. }
  17629. //random_uuid(guid);
  17630. strncpy(guid, str+6, 36); //copy guid
  17631. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17632. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17633. {
  17634. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17635. }
  17636. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17637. OCPP_insert_transaction_msg(NO, str);
  17638. memset(str,0,ARRAY_SIZE(str));
  17639. }
  17640. }
  17641. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17642. fclose(fptr1);
  17643. remove(TempStopTransaction); // remove the original file
  17644. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17645. }
  17646. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17647. {
  17648. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17649. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17650. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17651. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17652. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17653. }
  17654. int GetWebSocketPingInterval(void)
  17655. {
  17656. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17657. }
  17658. int GetServerSign(void)
  17659. {
  17660. return server_sign;
  17661. }
  17662. uint8_t GetOcppSecurityProfile()
  17663. {
  17664. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17665. }
  17666. void GetOcppChargerBoxId(uint8_t *data)
  17667. {
  17668. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17669. }
  17670. void GetOcppSecurityPassword(uint8_t *data)
  17671. {
  17672. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17673. }
  17674. void SetOcppVersion(uint8_t *version)
  17675. {
  17676. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17677. DEBUG_INFO("ocpp version: %s\n", version);
  17678. if(strstr((char*)version, "ocpp1.6") != NULL)
  17679. {
  17680. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17681. }
  17682. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17683. {
  17684. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17685. system("pkill OcppBackend");
  17686. }
  17687. }
  17688. void SetServerSign(int value)
  17689. {
  17690. server_sign = value;
  17691. }
  17692. int GetBootNotificationInterval(void)
  17693. {
  17694. return BootNotificationInterval;
  17695. }
  17696. int GetInternetConn(void)
  17697. {
  17698. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17699. }
  17700. int GetBackendConnectionTimeout(void)
  17701. {
  17702. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17703. }
  17704. int isConnectorInitMode(int gun_index)
  17705. {
  17706. int tempIndex = 0;
  17707. int result = TRUE;
  17708. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17709. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17710. {
  17711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17712. {
  17713. tempIndex = ((gun_index==2) ? 1: 0);
  17714. }
  17715. else
  17716. {
  17717. tempIndex = gun_index;
  17718. }
  17719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17720. {
  17721. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17722. {
  17723. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17724. } //end of the same index
  17725. }//end of for CHAdeMO_QUANTITY
  17726. }
  17727. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17728. {
  17729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17730. {
  17731. tempIndex = ((gun_index==2) ? 1: 0);
  17732. }
  17733. else
  17734. {
  17735. tempIndex = gun_index;
  17736. }
  17737. for (int index = 0; index < CCS_QUANTITY; index++)
  17738. {
  17739. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17740. {
  17741. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17742. } //end of the same index
  17743. } // end of for CCS_QUANTITY
  17744. }
  17745. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17746. {
  17747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17748. {
  17749. tempIndex = ((gun_index==2) ? 1: 0);
  17750. }
  17751. else
  17752. {
  17753. tempIndex = gun_index;
  17754. }
  17755. for (int index = 0; index < GB_QUANTITY; index++)
  17756. {
  17757. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17758. {
  17759. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17760. } //end of the same index
  17761. } // end of for GB_QUANTITY
  17762. }
  17763. else if(gunType[gun_index] == GUN_TYPE_DO)
  17764. {
  17765. tempIndex = gun_index;
  17766. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17767. {
  17768. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17769. {
  17770. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17771. } //end of the same index
  17772. }
  17773. }
  17774. else
  17775. {
  17776. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17777. {
  17778. tempIndex = 2;
  17779. }
  17780. else
  17781. {
  17782. tempIndex = gun_index;
  17783. }
  17784. for (int index = 0; index < AC_QUANTITY; index++)
  17785. {
  17786. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17787. {
  17788. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17789. }//end of the same index
  17790. }//end of for AC_QUANTITY
  17791. }
  17792. return result;
  17793. }
  17794. void refreshProcDogTimer()
  17795. {
  17796. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17797. }
  17798. void InitialSystemValue(void)
  17799. {
  17800. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17801. locallistVersion=0;
  17802. BootNotificationInterval = 0;
  17803. authorizeRetryTimes = 0;
  17804. GunStatusInterval = 10;
  17805. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17806. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17807. //Hear Beat
  17808. HeartBeatWithNOResponse = 0;
  17809. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17810. FirstHeartBeat = 0;
  17811. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17812. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17813. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17814. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17815. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17816. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17817. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17818. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17819. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17820. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17821. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17822. //Status && ConnectorPlugIn Setting
  17823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17824. {
  17825. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17826. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17827. }
  17828. for (int index = 0; index < CCS_QUANTITY; index++)
  17829. {
  17830. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17831. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17832. }
  17833. for (int index = 0; index < GB_QUANTITY; index++)
  17834. {
  17835. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17836. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17837. }
  17838. for (int index = 0; index < AC_QUANTITY; index++)
  17839. {
  17840. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17841. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17842. }
  17843. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17844. {
  17845. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17846. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17847. }
  17848. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17849. {
  17850. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17851. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17852. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17853. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17854. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17855. }
  17856. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17857. refreshStartTimer(&clientTime.Heartbeat);
  17858. sleep(1);
  17859. }
  17860. void LWS_Send(char *str)
  17861. {
  17862. //=====================================================
  17863. // Check InternetConn 0: disconnected, 1: connected
  17864. //====================================================
  17865. if(GetOcppConnStatus() == 0)
  17866. {
  17867. DEBUG_INFO("offline now !!!\n");
  17868. return;
  17869. }
  17870. // Only disable isWebsocketSendable operation initiated by charger
  17871. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17872. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17873. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17874. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17875. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17876. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17877. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17878. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17879. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17880. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17881. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17882. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17883. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17884. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17885. {
  17886. isWebsocketSendable = 0;
  17887. }
  17888. pthread_mutex_lock(&lock_send);
  17889. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17890. sprintf((char *)SendBuffer, "%s", str);
  17891. SendBufLen = strlen(str);
  17892. pthread_mutex_unlock(&lock_send);
  17893. lws_callback_on_writable(wsi_client);
  17894. //lws_service(context, 0);
  17895. //sleep(1);
  17896. }
  17897. void LWS_SendNow(char *str)
  17898. {
  17899. //=====================================================
  17900. // Check InternetConn 0: disconnected, 1: connected
  17901. //====================================================
  17902. if(GetOcppConnStatus() == 0)
  17903. {
  17904. DEBUG_INFO("offline now !!!\n");
  17905. return;
  17906. }
  17907. // Only disable isWebsocketSendable operation initiated by charger
  17908. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17909. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17910. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17911. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17912. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17913. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17914. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17915. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17916. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17917. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17918. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17919. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17920. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17921. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17922. {
  17923. isWebsocketSendable = 0;
  17924. }
  17925. pthread_mutex_lock(&lock_send);
  17926. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17927. sprintf((char *)SendBuffer, "%s", str);
  17928. SendBufLen = strlen(str);
  17929. pthread_mutex_unlock(&lock_send);
  17930. lws_callback_on_writable(wsi_client);
  17931. lws_service(context, 0);
  17932. //sleep(1);
  17933. }