MessageHandler.c 887 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075
  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 HeartBeat Response Not Receive Counts
  82. //============================================
  83. static int HeartBeatWithNOResponse = 0;
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  97. struct ClientTime
  98. {
  99. struct timespec Heartbeat;
  100. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  101. struct timespec StartTransaction;
  102. struct timespec StopTransaction;
  103. struct timespec MeterValues[CONNECTOR_QUANTITY];
  104. struct timespec RemoteStartWait;
  105. }clientTime;
  106. typedef union
  107. {
  108. //Operations Initiated by Central System
  109. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  110. struct
  111. {
  112. //CsMsgValue[0]
  113. unsigned char StatusNotificationReq:1; //bit 0,
  114. unsigned char StatusNotificationConf:1; //bit 1,
  115. unsigned char TriggerMeterValue:1; //bit 2,
  116. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  117. unsigned char isOnCharging:1; //bit 4.
  118. unsigned char :3; //bit 5~7
  119. }bits[CONNECTOR_QUANTITY];
  120. }CpinitiateMsg;
  121. CpinitiateMsg cpinitateMsg;
  122. //GetConfiguration Array
  123. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  125. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  126. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  127. #if 0
  128. static char *ChargePointErrorCodeStr[] = {
  129. MACROSTR(ConnectorLockFailure),
  130. MACROSTR(EVCommunicationError),
  131. MACROSTR(GroundFailure),
  132. MACROSTR(HighTemperature),
  133. MACROSTR(InternalError),
  134. MACROSTR(LocalListConflict),
  135. MACROSTR(NoError),
  136. MACROSTR(OtherError),
  137. MACROSTR(OverCurrentFailure),
  138. MACROSTR(OverVoltage),
  139. MACROSTR(PowerMeterFailure),
  140. MACROSTR(PowerSwitchFailure),
  141. MACROSTR(ReaderFailure),
  142. MACROSTR(ResetFailure),
  143. MACROSTR(UnderVoltage),
  144. MACROSTR(WeakSignal)
  145. };
  146. #endif
  147. static char * ChargePointStatusStr[] = {
  148. MACROSTR(Available),
  149. MACROSTR(Preparing),
  150. MACROSTR(Charging),
  151. MACROSTR(SuspendedEVSE),
  152. MACROSTR(SuspendedEV),
  153. MACROSTR(Finishing),
  154. MACROSTR(Reserved),
  155. MACROSTR(Unavailable),
  156. MACROSTR(Faulted)
  157. };
  158. static char *RegistrationStatusStr[] = {
  159. MACROSTR(Accepted),
  160. MACROSTR(Pending),
  161. MACROSTR(Rejected)
  162. };
  163. static char *AvailabilityTypeStr[] = {
  164. MACROSTR(Inoperative),
  165. MACROSTR(Operative)
  166. };
  167. static char *AvailabilityStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Scheduled)
  171. };
  172. static char *ConfigurationStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(RebootRequired),
  176. MACROSTR(NotSupported)
  177. };
  178. static char *ClearCacheStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected)
  181. };
  182. static char *ChargingProfilePurposeTypeStr[] = {
  183. MACROSTR(ChargePointMaxProfile),
  184. MACROSTR(TxDefaultProfile),
  185. MACROSTR(TxProfile)
  186. };
  187. static char *ChargingProfileStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(NotSupported)
  191. };
  192. static char *ClearChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Unknown)
  195. };
  196. static char *GetCompositeScheduleStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected)
  199. };
  200. static char *UpdateTypeStr[] = {
  201. MACROSTR(Differential),
  202. MACROSTR(Full)
  203. };
  204. static char *UpdateStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Failed),
  207. MACROSTR(NotSupported),
  208. MACROSTR(VersionMismatch)
  209. };
  210. static char *RemoteStartStopStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Rejected)
  213. };
  214. static char *ReservationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Faulted),
  217. MACROSTR(Occupied),
  218. MACROSTR(Rejected),
  219. MACROSTR(Unavailable)
  220. };
  221. static char *ResetTypeStr[] = {
  222. MACROSTR(Hard),
  223. MACROSTR(Soft)
  224. };
  225. static char *ResetStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Rejected)
  228. };
  229. static char * DiagnosticsStatusStr[] = {
  230. MACROSTR(Idle),
  231. MACROSTR(Uploaded),
  232. MACROSTR(UploadFailed),
  233. MACROSTR(Uploading)
  234. };
  235. static char * FirmwareStatusStr[] = {
  236. MACROSTR(Downloaded),
  237. MACROSTR(DownloadFailed),
  238. MACROSTR(Downloading),
  239. MACROSTR(Idle),
  240. MACROSTR(InstallationFailed),
  241. MACROSTR(Installing),
  242. MACROSTR(Installed)
  243. };
  244. static char * MessageTriggerStr[] = {
  245. MACROSTR(BootNotification),
  246. MACROSTR(DiagnosticsStatusNotification),
  247. MACROSTR(FirmwareStatusNotification),
  248. MACROSTR(Heartbeat),
  249. MACROSTR(MeterValues),
  250. MACROSTR(StatusNotification)
  251. };
  252. static char * TriggerMessageStatusStr[] = {
  253. MACROSTR(Accepted),
  254. MACROSTR(Rejected),
  255. MACROSTR(NotImplemented)
  256. };
  257. static char * UnlockStatusStr[] = {
  258. MACROSTR(Unlocked),
  259. MACROSTR(UnlockFailed),
  260. MACROSTR(NotSupported)
  261. };
  262. #if 0
  263. static char * StopTransactionReasonStr[] = {
  264. MACROSTR(EmergencyStop),
  265. MACROSTR(EVDisconnected),
  266. MACROSTR(HardReset),
  267. MACROSTR(Local),
  268. MACROSTR(Other),
  269. MACROSTR(PowerLoss),
  270. MACROSTR(Reboot),
  271. MACROSTR(Remote),
  272. MACROSTR(SoftReset),
  273. MACROSTR(UnlockCommand),
  274. MACROSTR(DeAuthorized)
  275. };
  276. #endif
  277. static char * CancelReservationStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected)
  280. };
  281. static char * ReadingContextStr[] = {
  282. MACROSTR(Interruption.Begin),
  283. MACROSTR(Interruption.End),
  284. MACROSTR(Other),
  285. MACROSTR(Sample.Clock),
  286. MACROSTR(Sample.Periodic),
  287. MACROSTR(Transaction.Begin),
  288. MACROSTR(Transaction.End),
  289. MACROSTR(Trigger)
  290. };
  291. static char * ValueFormatStr[] = {
  292. MACROSTR(Raw),
  293. MACROSTR(SignedData)
  294. };
  295. static char * MeasurandStr[] = {
  296. MACROSTR(Current.Export),
  297. MACROSTR(Current.Import),
  298. MACROSTR(Current.Offered),
  299. MACROSTR(Energy.Active.Export.Register),
  300. MACROSTR(Energy.Active.Import.Register),
  301. MACROSTR(Energy.Reactive.Export.Register),
  302. MACROSTR(Energy.Reactive.Import.Register),
  303. MACROSTR(Energy.Active.Export.Interval),
  304. MACROSTR(Energy.Active.Import.Interval),
  305. MACROSTR(Energy.Reactive.Export.Interval),
  306. MACROSTR(Energy.Reactive.Import.Interval),
  307. MACROSTR(Frequency),
  308. MACROSTR(Power.Active.Export),
  309. MACROSTR(Power.Active.Import),
  310. MACROSTR(Power.Factor),
  311. MACROSTR(Power.Offered),
  312. MACROSTR(Power.Reactive.ExportMACROSTR),
  313. MACROSTR(Power.Reactive.Import),
  314. MACROSTR(RPM),
  315. MACROSTR(SoC),
  316. MACROSTR(Temperature),
  317. MACROSTR(Voltage)
  318. };
  319. static char * LocationStr[] = {
  320. MACROSTR(Body),
  321. MACROSTR(Cable),
  322. MACROSTR(EV),
  323. MACROSTR(Inlet),
  324. MACROSTR(Outlet)
  325. };
  326. static char * PhaseStr[] = {
  327. MACROSTR(L1),
  328. MACROSTR(L2),
  329. MACROSTR(L3),
  330. MACROSTR(N),
  331. MACROSTR(L1-N),
  332. MACROSTR(L2-N),
  333. MACROSTR(L3-N),
  334. MACROSTR(L1-L2),
  335. MACROSTR(L2-L3),
  336. MACROSTR(L3-L1)
  337. };
  338. static char * UnitOfMeasureStr[] = {
  339. MACROSTR(Wh),
  340. MACROSTR(kWh),
  341. MACROSTR(varh),
  342. MACROSTR(kvarh),
  343. MACROSTR(W),
  344. MACROSTR(kW),
  345. MACROSTR(VA),
  346. MACROSTR(kVA),
  347. MACROSTR(var),
  348. MACROSTR(kvar),
  349. MACROSTR(A),
  350. MACROSTR(V),
  351. MACROSTR(Celsius),
  352. MACROSTR(Fahrenheit),
  353. MACROSTR(K),
  354. MACROSTR(Percent)
  355. };
  356. //=========================================
  357. // Save configuration
  358. //=========================================
  359. int runShellCmd(const char*cmd)
  360. {
  361. int result = FAIL;
  362. char buf[256];
  363. FILE *fp;
  364. fp = popen(cmd, "r");
  365. if(fp != NULL)
  366. {
  367. while(fgets(buf, sizeof(buf), fp) != NULL)
  368. {
  369. DEBUG_INFO("%s\n", buf);
  370. }
  371. result = PASS;
  372. }
  373. pclose(fp);
  374. return result;
  375. }
  376. int StoreUsrConfigData(struct SysConfigData *UsrData)
  377. {
  378. int result = PASS;
  379. int fd,wrd;
  380. unsigned int i,Chk;
  381. unsigned char *ptr, *BufTmp;
  382. int MtdBlockSize = 0x300000;
  383. Chk=0;
  384. ptr=(unsigned char *)UsrData;
  385. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  386. {
  387. memset(BufTmp,0,MtdBlockSize);
  388. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  389. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  390. Chk+=*(BufTmp+i);
  391. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  392. // Output configuration to file.
  393. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  394. if (fd < 0)
  395. {
  396. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  397. free(BufTmp);
  398. return 0;
  399. }
  400. wrd=write(fd, BufTmp, MtdBlockSize);
  401. close(fd);
  402. if(wrd<MtdBlockSize)
  403. {
  404. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  405. free(BufTmp);
  406. return 0;
  407. }
  408. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  409. DEBUG_INFO("Erase /dev/mtd10.\n");
  410. runShellCmd("flash_erase /dev/mtd10 0 0");
  411. DEBUG_INFO("Write /dev/mtd10.\n");
  412. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  413. DEBUG_INFO("Erase /dev/mtd11.\n");
  414. runShellCmd("flash_erase /dev/mtd11 0 0");
  415. DEBUG_INFO("Write /dev/mtd11.\n");
  416. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  417. system("rm -f /mnt/EvseConfig.bin");
  418. DEBUG_INFO("EvseConfig write to flash OK\n");
  419. }
  420. else
  421. {
  422. DEBUG_ERROR("alloc BlockSize NG\r\n");
  423. result = FAIL;
  424. }
  425. if(BufTmp!=NULL)
  426. free(BufTmp);
  427. return result;
  428. }
  429. //=========================================
  430. // Sqlite3 related function
  431. //=========================================
  432. static int selectSqlCount = 0;
  433. static int callback(void *data, int argc, char **argv, char **azColName){
  434. int i;
  435. //printf("%s: ", (const char*)data);
  436. selectSqlCount = argc;
  437. for(i = 0; i<argc; i++){
  438. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  439. }
  440. //printf("\n");
  441. return 0;
  442. }
  443. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  444. //int i;
  445. //printf("%s:\n", (const char*)data);
  446. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  447. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  448. return 0;
  449. }
  450. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  451. //printf("%s:\n", (const char*)data);
  452. //idTag
  453. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  455. //parentIdTag
  456. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  457. //expir_date
  458. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  459. //status
  460. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  461. //version
  462. if(columenCount > 5)
  463. idTagQuery.listVersionInt = atoi(columnValue[5]);
  464. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  465. return 0;
  466. }
  467. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  468. {
  469. // localversion = argv[5] ? atoi(argv[5]) : 0;
  470. // printf("localversion=%d\n", localversion);
  471. return 0;
  472. }
  473. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  474. {
  475. for (int i = 0; i < n_columns; i++)
  476. {
  477. DEBUG_INFO("%s\t", col_values[i]);
  478. }
  479. DEBUG_INFO("\n");
  480. return 0;
  481. }
  482. int OCPP_cleanLocalCache()
  483. {
  484. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  485. char *errMsg = 0;
  486. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  487. if (SQLITE_OK != rc)
  488. {
  489. DEBUG_INFO("SQL error: %s\n",errMsg);
  490. return FALSE;
  491. }
  492. return TRUE;
  493. }
  494. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  495. {
  496. int isSuccess = TRUE;
  497. int ret = 0;
  498. //const char* data = "Callback function called";
  499. char sql[300];
  500. char zErrMsg[200];
  501. memset(sql, 0, 300);
  502. memset(zErrMsg, 0, 200);
  503. 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);
  504. //* Execute SQL statement */
  505. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  506. if( ret != SQLITE_OK )
  507. {
  508. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  509. isSuccess = FALSE;
  510. }
  511. return isSuccess;
  512. }
  513. void OCPP_getIdTagFromLocalCache(char idTag[])
  514. {
  515. int rc = 0;
  516. char sql[100];
  517. char zErrMsg[100];
  518. memset(sql, 0, 100);
  519. memset(zErrMsg, 0, 100);
  520. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  521. memset(&idTagQuery, 0, sizeof(idTagQuery));
  522. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  523. /* Execute SQL statement */
  524. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  525. if( rc != SQLITE_OK )
  526. {
  527. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  528. }
  529. }
  530. void OCPP_getListVerion()
  531. {
  532. int rc = 0;
  533. // const char* data = "Callback function called";
  534. char sql[100];
  535. char zErrMsg[100];
  536. memset(sql, 0, 100);
  537. memset(zErrMsg, 0, 100);
  538. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  539. /* Execute SQL statement */
  540. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  541. if( rc != SQLITE_OK )
  542. {
  543. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  544. }
  545. }
  546. void OCPP_get_TableAuthlocalAllData(void)
  547. {
  548. int rc = 0;
  549. char sql[100];
  550. char zErrMsg[100];
  551. memset(sql, 0, 100);
  552. memset(zErrMsg, 0, 100);
  553. sprintf(sql,"select * from ocpp_auth_local ");
  554. /* Execute SQL statement */
  555. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  556. if( rc != SQLITE_OK )
  557. {
  558. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  559. }
  560. //return ver;
  561. }
  562. int OCPP_cleanLocalList()
  563. {
  564. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  565. char *errMsg = 0;
  566. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  567. if (SQLITE_OK != rc)
  568. {
  569. DEBUG_INFO("%s\n",errMsg);
  570. return FALSE;
  571. }
  572. return TRUE;
  573. }
  574. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  575. {
  576. int isSuccess = FALSE;
  577. int ret = 0;
  578. //const char* data = "Callback function called";
  579. char sql[300];
  580. char zErrMsg[200];
  581. memset(sql, 0, 300);
  582. memset(zErrMsg, 0, 200);
  583. 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);
  584. //* Execute SQL statement */
  585. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  586. if( ret != SQLITE_OK )
  587. {
  588. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  589. return isSuccess;
  590. }
  591. memset(sql, 0, 300);
  592. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  593. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  594. if( ret != SQLITE_OK )
  595. {
  596. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  597. return isSuccess;
  598. }
  599. isSuccess = TRUE;
  600. return isSuccess;
  601. }
  602. void OCPP_getIdTagFromLocalList(char idTag[])
  603. {
  604. int rc = 0;
  605. // const char* data = "Callback function called";
  606. char sql[100];
  607. char zErrMsg[100];
  608. memset(sql, 0, 100);
  609. memset(zErrMsg, 0, 100);
  610. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  611. memset(&idTagQuery, 0, sizeof(idTagQuery));
  612. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  613. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  614. /* Execute SQL statement */
  615. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  616. if( rc != SQLITE_OK )
  617. {
  618. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  619. }
  620. //return ver;
  621. }
  622. void OCPP_deleteIdTagFromLocalList(char idTag[])
  623. {
  624. //int ver = 0;
  625. //int isSuccess = FALSE;
  626. int rc = 0;
  627. char sql[100];
  628. char zErrMsg[100];
  629. memset(sql, 0, 100);
  630. memset(zErrMsg, 0, 100);
  631. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  632. //* Execute SQL statement */
  633. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  634. if( rc != SQLITE_OK )
  635. {
  636. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  637. }
  638. }
  639. int getCurrentYear()
  640. {
  641. int result = 0;
  642. time_t CurrentTime;
  643. struct tm *tm;
  644. CurrentTime = time(NULL);
  645. tm=localtime(&CurrentTime);
  646. result = (tm->tm_year + 1900);
  647. return result;
  648. }
  649. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  650. {
  651. int result = PASS;
  652. char* errMsg = NULL;
  653. char sqlStr[8192];
  654. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  655. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  656. {
  657. result = FAIL;
  658. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  659. }
  660. 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));
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  665. }
  666. return result;
  667. }
  668. //==========================================
  669. // Check time passed since today
  670. //==========================================
  671. long long DiffTimebWithNow(struct timeb ST)
  672. {
  673. //return milli-second
  674. struct timeb ET;
  675. long long StartTime,StopTime;
  676. ftime(&ET);
  677. StartTime=(long long)ST.time;
  678. StopTime=(long long)ET.time;
  679. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  680. }
  681. int getTimePassSinceToday(uint8_t gun_index)
  682. {
  683. int result = -1;
  684. static time_t lastTime[4];
  685. time_t t;
  686. struct tm *tmStartToday;
  687. struct timeb tbStartToday;
  688. t=time(NULL);
  689. if(difftime(t, lastTime[gun_index])>0)
  690. {
  691. tmStartToday=localtime(&t);
  692. tmStartToday->tm_hour = 0;
  693. tmStartToday->tm_min = 0;
  694. tmStartToday->tm_sec = 0;
  695. tbStartToday.time = mktime(tmStartToday);
  696. tbStartToday.millitm = 0;
  697. result = DiffTimebWithNow(tbStartToday)/1000;
  698. lastTime[gun_index] = t;
  699. }
  700. return result;
  701. }
  702. void getNowDatetime(uint8_t *data)
  703. {
  704. time_t t = time(NULL);
  705. struct tm tm = *localtime(&t);
  706. 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);
  707. }
  708. int syncDateTimeRTC(uint8_t *data)
  709. {
  710. struct ParsingResult
  711. {
  712. int result;
  713. int scanedElement;
  714. int year;
  715. int month;
  716. int mday;
  717. int hour;
  718. int min;
  719. int sec;
  720. int tz_hour;
  721. int tz_min;
  722. float minSec;
  723. }result;
  724. struct tm tmOrg;
  725. struct tm *tmTarget;
  726. struct timeb tbTarget;
  727. char buf[128];
  728. memset(&result, 0x00, sizeof(struct ParsingResult));
  729. result.result = PASS;
  730. if(strstr((char*)data, ".") != NULL)
  731. {
  732. // Original data with mini second
  733. if(strstr((char*)data, "Z") != NULL)
  734. {
  735. // Original data with Z
  736. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  737. &result.year,
  738. &result.month,
  739. &result.mday,
  740. &result.hour,
  741. &result.min,
  742. &result.sec,
  743. &result.minSec);
  744. }
  745. else
  746. {
  747. // Original data without Z
  748. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  749. &result.year,
  750. &result.month,
  751. &result.mday,
  752. &result.hour,
  753. &result.min,
  754. &result.sec,
  755. &result.minSec,
  756. &result.tz_hour,
  757. &result.tz_min);
  758. }
  759. }
  760. else
  761. {
  762. // Original data without mini second
  763. if(strstr((char*)data, "Z") != NULL)
  764. {
  765. // Original data with Z
  766. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  767. &result.year,
  768. &result.month,
  769. &result.mday,
  770. &result.hour,
  771. &result.min,
  772. &result.sec);
  773. }
  774. else
  775. {
  776. // Original data without Z
  777. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  778. &result.year,
  779. &result.month,
  780. &result.mday,
  781. &result.hour,
  782. &result.min,
  783. &result.sec,
  784. &result.tz_hour,
  785. &result.tz_min);
  786. }
  787. }
  788. tmOrg.tm_year = result.year - 1900;
  789. tmOrg.tm_mon = result.month - 1;
  790. tmOrg.tm_mday = result.mday;
  791. tmOrg.tm_hour = result.hour;
  792. tmOrg.tm_min = result.min;
  793. tmOrg.tm_sec = result.sec;
  794. tmOrg.tm_gmtoff = 0;
  795. tbTarget.time = mktime(&tmOrg);
  796. tbTarget.timezone = 0;
  797. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  798. tmTarget = gmtime(&tbTarget.time);
  799. 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);
  800. //DEBUG_INFO(" org date time: %s\n", data);
  801. //DEBUG_INFO("parse date time: %s\n", buf);
  802. system(buf);
  803. system("/sbin/hwclock -w --systohc");
  804. if(result.scanedElement < 6)
  805. result.result = FAIL;
  806. return result.result;
  807. }
  808. //==========================================
  809. // GetCompositeSchedule logic related function
  810. //==========================================
  811. int DiffTimebSec(struct timeb ST, struct timeb ET)
  812. {
  813. //return milli-second
  814. unsigned int StartTime,StopTime;
  815. StartTime=(unsigned int)ST.time;
  816. StopTime=(unsigned int)ET.time;
  817. return (StopTime-StartTime);
  818. }
  819. int DiffTimebWithNowSec(struct timeb ST)
  820. {
  821. //return milli-second
  822. struct timeb ET;
  823. unsigned int StartTime,StopTime;
  824. ftime(&ET);
  825. StartTime=(unsigned int)ST.time;
  826. StopTime=(unsigned int)ET.time;
  827. return (StopTime-StartTime);
  828. }
  829. int getStartStop(uint8_t *start, uint8_t *stop)
  830. {
  831. int result = -1;
  832. struct tm tmStart;
  833. struct timeb tbStart;
  834. struct tm tmStop;
  835. struct timeb tbStop;
  836. 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) &&
  837. (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))
  838. {
  839. //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);
  840. //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);
  841. tmStart.tm_year -= 1900;
  842. tmStart.tm_mon -= 1;
  843. tbStart.time = mktime(&tmStart);
  844. tbStart.millitm = 0;
  845. tmStop.tm_year -= 1900;
  846. tmStop.tm_mon -= 1;
  847. tbStop.time = mktime(&tmStop);
  848. tbStop.millitm = 0;
  849. result = DiffTimebSec(tbStart, tbStop);
  850. //DEBUG_INFO("getStartStop(): %d\n", result);
  851. }
  852. else
  853. {
  854. DEBUG_WARN("Start or stop date parsing error.\r\n");
  855. }
  856. return result;
  857. }
  858. int isOvertNow(uint8_t *start)
  859. {
  860. int result = NO;
  861. struct ParsingResult
  862. {
  863. int result;
  864. int scanedElement;
  865. int year;
  866. int month;
  867. int mday;
  868. int hour;
  869. int min;
  870. int sec;
  871. int tz_hour;
  872. int tz_min;
  873. float minSec;
  874. }parsingResult;
  875. struct tm tmStart;
  876. struct timeb tbStart;
  877. if(strstr((char*)start, ".") != NULL)
  878. {
  879. // Original data with mini second
  880. if(strstr((char*)start, "Z") != NULL)
  881. {
  882. // Original data with Z
  883. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  884. &parsingResult.year,
  885. &parsingResult.month,
  886. &parsingResult.mday,
  887. &parsingResult.hour,
  888. &parsingResult.min,
  889. &parsingResult.sec,
  890. &parsingResult.minSec);
  891. }
  892. else
  893. {
  894. // Original data without Z
  895. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  896. &parsingResult.year,
  897. &parsingResult.month,
  898. &parsingResult.mday,
  899. &parsingResult.hour,
  900. &parsingResult.min,
  901. &parsingResult.sec,
  902. &parsingResult.minSec,
  903. &parsingResult.tz_hour,
  904. &parsingResult.tz_min);
  905. }
  906. }
  907. else
  908. {
  909. // Original data without mini second
  910. if(strstr((char*)start, "Z") != NULL)
  911. {
  912. // Original data with Z
  913. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  914. &parsingResult.year,
  915. &parsingResult.month,
  916. &parsingResult.mday,
  917. &parsingResult.hour,
  918. &parsingResult.min,
  919. &parsingResult.sec);
  920. }
  921. else
  922. {
  923. // Original data without Z
  924. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  925. &parsingResult.year,
  926. &parsingResult.month,
  927. &parsingResult.mday,
  928. &parsingResult.hour,
  929. &parsingResult.min,
  930. &parsingResult.sec,
  931. &parsingResult.tz_hour,
  932. &parsingResult.tz_min);
  933. }
  934. }
  935. if(parsingResult.scanedElement >= 6)
  936. {
  937. tmStart.tm_year = parsingResult.year - 1900;
  938. tmStart.tm_mon = parsingResult.month - 1;
  939. tmStart.tm_mday = parsingResult.mday;
  940. tmStart.tm_hour = parsingResult.hour;
  941. tmStart.tm_min = parsingResult.min;
  942. tmStart.tm_sec = parsingResult.sec;
  943. tmStart.tm_gmtoff = 0;
  944. tbStart.time = mktime(&tmStart);
  945. tbStart.timezone = 0;
  946. tbStart.millitm = 0;
  947. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  948. if(DiffTimebWithNowSec(tbStart) <= 0)
  949. result = NO;
  950. else
  951. result = YES;
  952. }
  953. else
  954. {
  955. DEBUG_WARN("Start date parsing error.\n");
  956. }
  957. return result;
  958. }
  959. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  960. {
  961. int result = -1;
  962. struct tm tmStart;
  963. struct timeb tbStart;
  964. struct tm tmStop;
  965. struct timeb tbStop;
  966. 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) &&
  967. (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))
  968. {
  969. tmStart.tm_year -= 1900;
  970. tmStart.tm_mon -= 1;
  971. tbStart.time = mktime(&tmStart);
  972. tbStart.millitm = 0;
  973. tmStop.tm_year -= 1900;
  974. tmStop.tm_mon -= 1;
  975. tbStop.time = mktime(&tmStop);
  976. tbStop.millitm = 0;
  977. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  978. }
  979. return result;
  980. }
  981. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  982. {
  983. FILE *fp;
  984. char profileFileName[128];
  985. char *line = NULL;
  986. size_t len = 0;
  987. time_t CurrentTime;
  988. struct tm *tmComposite;
  989. struct StructChargingProfile maxProfile;
  990. uint8_t limitMax=0;
  991. int compositePeriodIdx = 0;
  992. CurrentTime = time(NULL);
  993. tmComposite=localtime(&CurrentTime);
  994. 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);
  995. if(isUnitA)
  996. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  997. else
  998. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  999. compositeProfile->ChargingSchedule.Duration = durationReq;
  1000. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1001. {
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1004. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1005. }
  1006. compositeProfile->ChargingProfileId = 0;
  1007. compositeProfile->StackLevel = 99 ;
  1008. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1009. maxProfile.ChargingProfileId = -1;
  1010. maxProfile.ChargingSchedule.Duration = -1;
  1011. system("rm -f /tmp/*.json");
  1012. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1013. // Search max profile
  1014. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1015. if((access(profileFileName, F_OK))!=-1)
  1016. {
  1017. fp = fopen(profileFileName, "r");
  1018. while(getline(&line, &len, fp) != -1)
  1019. {
  1020. json_object *obj = NULL;
  1021. obj = json_tokener_parse(line);
  1022. if(is_error(obj))
  1023. {
  1024. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1025. }
  1026. else
  1027. {
  1028. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1029. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1030. )
  1031. {
  1032. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1033. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1034. )
  1035. {
  1036. struct tm tmFrom, tmTo;
  1037. struct timeb tbFrom, tbTo;
  1038. 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) &&
  1039. (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))
  1040. {
  1041. tmFrom.tm_year -= 1900;
  1042. tmFrom.tm_mon -= 1;
  1043. tbFrom.time = mktime(&tmFrom);
  1044. tmTo.tm_year -= 1900;
  1045. tmTo.tm_mon -= 1;
  1046. tbTo.time = mktime(&tmTo);
  1047. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1048. {
  1049. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1050. {
  1051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1053. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1054. }
  1055. maxProfile.ChargingProfileId = -1;
  1056. maxProfile.StackLevel = -1;
  1057. if(maxProfile.ChargingProfileId == -1)
  1058. DEBUG_INFO("MaxProfile found.\n");
  1059. else
  1060. DEBUG_INFO("MaxProfile updated.\n");
  1061. // Required item
  1062. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1063. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1064. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1065. if(isUnitA)
  1066. {
  1067. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1068. 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++)
  1069. {
  1070. 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"));
  1071. 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?
  1072. 3:
  1073. 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")));
  1074. 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")));
  1075. }
  1076. }
  1077. else
  1078. {
  1079. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1080. 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++)
  1081. {
  1082. 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"));
  1083. 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?
  1084. 3:
  1085. 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")));
  1086. 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));
  1087. }
  1088. }
  1089. // Optional item
  1090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1091. {
  1092. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1093. }
  1094. else
  1095. {
  1096. sprintf((char*)maxProfile.ValidFrom, " ");
  1097. }
  1098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1099. {
  1100. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1101. }
  1102. else
  1103. {
  1104. sprintf((char*)maxProfile.ValidTo, " ");
  1105. }
  1106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1107. {
  1108. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1109. }
  1110. else
  1111. {
  1112. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1113. }
  1114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1115. {
  1116. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1117. }
  1118. else
  1119. {
  1120. maxProfile.TransactionId = -1;
  1121. }
  1122. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1123. {
  1124. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1125. }
  1126. else
  1127. {
  1128. maxProfile.ChargingSchedule.Duration = 86400;
  1129. }
  1130. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1131. {
  1132. 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")));
  1133. }
  1134. else
  1135. {
  1136. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1137. }
  1138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1139. {
  1140. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1141. }
  1142. else
  1143. {
  1144. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. else
  1150. {
  1151. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1152. {
  1153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1155. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1156. }
  1157. maxProfile.ChargingProfileId = -1;
  1158. maxProfile.StackLevel = -1;
  1159. if(maxProfile.ChargingProfileId == -1)
  1160. DEBUG_INFO("MaxProfile found.\n");
  1161. else
  1162. DEBUG_INFO("MaxProfile updated.\n");
  1163. // Required item
  1164. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1165. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1166. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1167. if(isUnitA)
  1168. {
  1169. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1170. 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++)
  1171. {
  1172. 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"));
  1173. 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?
  1174. 3:
  1175. 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")));
  1176. 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")));
  1177. }
  1178. }
  1179. else
  1180. {
  1181. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1182. 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++)
  1183. {
  1184. 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"));
  1185. 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?
  1186. 3:
  1187. 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")));
  1188. 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));
  1189. }
  1190. }
  1191. // Optional item
  1192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1193. {
  1194. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1195. }
  1196. else
  1197. {
  1198. sprintf((char*)maxProfile.ValidFrom, " ");
  1199. }
  1200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1201. {
  1202. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1203. }
  1204. else
  1205. {
  1206. sprintf((char*)maxProfile.ValidTo, " ");
  1207. }
  1208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1209. {
  1210. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1211. }
  1212. else
  1213. {
  1214. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1215. }
  1216. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1217. {
  1218. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1219. }
  1220. else
  1221. {
  1222. maxProfile.TransactionId = -1;
  1223. }
  1224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1225. {
  1226. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1227. }
  1228. else
  1229. {
  1230. maxProfile.ChargingSchedule.Duration = 86400;
  1231. }
  1232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1233. {
  1234. 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")));
  1235. }
  1236. else
  1237. {
  1238. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1239. }
  1240. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1241. {
  1242. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1243. }
  1244. else
  1245. {
  1246. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1247. }
  1248. }
  1249. }
  1250. }
  1251. json_object_put(obj);
  1252. }
  1253. fclose(fp);
  1254. /*
  1255. if(maxProfile.ChargingProfileId !=-1)
  1256. {
  1257. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1258. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1259. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1260. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1261. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1262. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1263. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1264. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1265. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1266. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1267. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1269. {
  1270. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1271. {
  1272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1275. }
  1276. }
  1277. }
  1278. else
  1279. DEBUG_INFO("MaxProfile not found.\n");
  1280. DEBUG_INFO("------------------------------------\n");*/
  1281. }
  1282. if(maxProfile.ChargingProfileId != -1)
  1283. {
  1284. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1285. {
  1286. if(maxProfile.ChargingSchedule.Duration != -1)
  1287. {
  1288. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1289. 0:
  1290. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1291. }
  1292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1293. {
  1294. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1295. {
  1296. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1297. 0:
  1298. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1299. if(idxPeriod > 0)
  1300. {
  1301. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1302. {
  1303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1310. {
  1311. if(maxProfile.ChargingSchedule.Duration != -1)
  1312. {
  1313. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1314. }
  1315. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1316. {
  1317. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1318. {
  1319. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1320. if(idxPeriod > 0)
  1321. {
  1322. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1323. {
  1324. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1333. {
  1334. if(maxProfile.ChargingSchedule.Duration != -1)
  1335. {
  1336. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1337. 0:
  1338. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1339. }
  1340. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1341. {
  1342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1343. {
  1344. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1345. 0:
  1346. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1347. if(idxPeriod > 0)
  1348. {
  1349. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1350. {
  1351. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. else
  1358. {
  1359. if(maxProfile.ChargingSchedule.Duration != -1)
  1360. {
  1361. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1362. 0:
  1363. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1364. }
  1365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1366. {
  1367. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1368. {
  1369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1370. 0:
  1371. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1372. if(idxPeriod > 0)
  1373. {
  1374. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1375. {
  1376. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. /*
  1384. DEBUG_INFO("MaxProfile after align.\n");
  1385. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1386. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1387. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1388. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1389. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1390. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1391. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1392. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1393. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1394. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1395. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1397. {
  1398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1399. {
  1400. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1401. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1402. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1403. }
  1404. }
  1405. DEBUG_INFO("------------------------------------\n");*/
  1406. }
  1407. // Find each profile period quantity
  1408. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1409. {
  1410. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1411. limitMax = idx+1;
  1412. }
  1413. if(maxProfile.ChargingProfileId != -1)
  1414. {
  1415. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1416. {
  1417. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1418. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1419. (maxProfile.ChargingSchedule.Duration > 0))
  1420. {
  1421. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1422. {
  1423. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1424. compositePeriodIdx++;
  1425. }
  1426. else
  1427. {
  1428. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1429. }
  1430. }
  1431. }
  1432. }
  1433. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1434. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1435. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1436. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1437. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1438. {
  1439. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1440. {
  1441. compositeProfile->ChargingProfileId = 1;
  1442. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1443. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1444. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1445. }
  1446. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1447. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1448. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1449. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1450. }
  1451. if(line)
  1452. free(line);
  1453. }
  1454. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1455. {
  1456. FILE *fp;
  1457. char profileFileName[128];
  1458. char *line = NULL;
  1459. size_t len = 0;
  1460. time_t CurrentTime;
  1461. struct tm *tmComposite;
  1462. struct StructChargingProfile maxProfile;
  1463. struct StructChargingProfile defaultTxProfile;
  1464. struct StructChargingProfile txProfile;
  1465. struct StructChargingSchedulePeriod tmpPeriod;
  1466. uint8_t limitMax=0;
  1467. uint8_t limitDef=0;
  1468. uint8_t limitTx=0;
  1469. int compositePeriodIdx = 0;
  1470. CurrentTime = time(NULL);
  1471. tmComposite=localtime(&CurrentTime);
  1472. 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);
  1473. if(isUnitA)
  1474. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1475. else
  1476. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1477. compositeProfile->ChargingSchedule.Duration = durationReq;
  1478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1479. {
  1480. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1482. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1483. }
  1484. compositeProfile->ChargingProfileId = 0;
  1485. compositeProfile->StackLevel = 99 ;
  1486. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1487. maxProfile.ChargingProfileId = -1;
  1488. defaultTxProfile.ChargingProfileId = -1;
  1489. txProfile.ChargingProfileId = -1;
  1490. maxProfile.ChargingSchedule.Duration = -1;
  1491. defaultTxProfile.ChargingSchedule.Duration = -1;
  1492. txProfile.ChargingSchedule.Duration = -1;
  1493. system("rm -f /tmp/*.json");
  1494. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1495. /*
  1496. * Search valid charging profile
  1497. */
  1498. //DEBUG_INFO("====================================\n");
  1499. // Search tx profile
  1500. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1501. if((access(profileFileName, F_OK))!=-1)
  1502. {
  1503. fp = fopen(profileFileName, "r");
  1504. while(getline(&line, &len, fp) != -1)
  1505. {
  1506. json_object *obj = NULL;
  1507. obj = json_tokener_parse(line);
  1508. if(is_error(obj))
  1509. {
  1510. DEBUG_ERROR("Parse txProfile from file error.\n");
  1511. }
  1512. else
  1513. {
  1514. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1515. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1516. )
  1517. {
  1518. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1519. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1520. )
  1521. {
  1522. struct tm tmFrom, tmTo;
  1523. struct timeb tbFrom, tbTo;
  1524. 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) &&
  1525. (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))
  1526. {
  1527. tmFrom.tm_year -= 1900;
  1528. tmFrom.tm_mon -= 1;
  1529. tbFrom.time = mktime(&tmFrom);
  1530. tmTo.tm_year -= 1900;
  1531. tmTo.tm_mon -= 1;
  1532. tbTo.time = mktime(&tmTo);
  1533. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1534. {
  1535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1536. {
  1537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1539. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1540. }
  1541. txProfile.ChargingProfileId = -1;
  1542. txProfile.StackLevel = -1;
  1543. if(txProfile.ChargingProfileId == -1)
  1544. DEBUG_INFO("TxProfile found.\n");
  1545. else
  1546. DEBUG_INFO("TxProfile updated.\n");
  1547. // Required item
  1548. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1549. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1550. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1551. if(isUnitA)
  1552. {
  1553. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1554. 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++)
  1555. {
  1556. 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"));
  1557. 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?
  1558. 3:
  1559. 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")));
  1560. 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")));
  1561. }
  1562. }
  1563. else
  1564. {
  1565. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1566. 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++)
  1567. {
  1568. 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"));
  1569. 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?
  1570. 3:
  1571. 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")));
  1572. 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));
  1573. }
  1574. }
  1575. // Optional item
  1576. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1577. {
  1578. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1579. }
  1580. else
  1581. {
  1582. sprintf((char*)txProfile.ValidFrom, " ");
  1583. }
  1584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1585. {
  1586. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1587. }
  1588. else
  1589. {
  1590. sprintf((char*)txProfile.ValidTo, " ");
  1591. }
  1592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1593. {
  1594. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1595. }
  1596. else
  1597. {
  1598. sprintf((char*)txProfile.RecurrencyKind, " ");
  1599. }
  1600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1601. {
  1602. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1603. }
  1604. else
  1605. {
  1606. txProfile.TransactionId = -1;
  1607. }
  1608. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1609. {
  1610. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1611. }
  1612. else
  1613. {
  1614. txProfile.ChargingSchedule.Duration = 86400;
  1615. }
  1616. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1617. {
  1618. 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")));
  1619. }
  1620. else
  1621. {
  1622. 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));
  1623. }
  1624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1625. {
  1626. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1627. }
  1628. else
  1629. {
  1630. txProfile.ChargingSchedule.MinChargingRate = -1;
  1631. }
  1632. }
  1633. }
  1634. }
  1635. else
  1636. {
  1637. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1638. {
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1641. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1642. }
  1643. txProfile.ChargingProfileId = -1;
  1644. txProfile.StackLevel = -1;
  1645. if(txProfile.ChargingProfileId == -1)
  1646. DEBUG_INFO("TxProfile found.\n");
  1647. else
  1648. DEBUG_INFO("TxProfile updated.\n");
  1649. // Required item
  1650. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1651. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1652. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1653. if(isUnitA)
  1654. {
  1655. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1656. 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++)
  1657. {
  1658. 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"));
  1659. 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?
  1660. 3:
  1661. 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")));
  1662. 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")));
  1663. }
  1664. }
  1665. else
  1666. {
  1667. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1668. 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++)
  1669. {
  1670. 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"));
  1671. 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?
  1672. 3:
  1673. 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")));
  1674. 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));
  1675. }
  1676. }
  1677. // Optional item
  1678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1679. {
  1680. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1681. }
  1682. else
  1683. {
  1684. sprintf((char*)txProfile.ValidFrom, " ");
  1685. }
  1686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1687. {
  1688. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1689. }
  1690. else
  1691. {
  1692. sprintf((char*)txProfile.ValidTo, " ");
  1693. }
  1694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1695. {
  1696. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1697. }
  1698. else
  1699. {
  1700. sprintf((char*)txProfile.RecurrencyKind, " ");
  1701. }
  1702. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1703. {
  1704. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1705. }
  1706. else
  1707. {
  1708. txProfile.TransactionId = -1;
  1709. }
  1710. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1711. {
  1712. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1713. }
  1714. else
  1715. {
  1716. txProfile.ChargingSchedule.Duration = 86400;
  1717. }
  1718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1719. {
  1720. 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")));
  1721. }
  1722. else
  1723. {
  1724. 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));
  1725. }
  1726. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1727. {
  1728. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1729. }
  1730. else
  1731. {
  1732. txProfile.ChargingSchedule.MinChargingRate = -1;
  1733. }
  1734. }
  1735. }
  1736. }
  1737. json_object_put(obj);
  1738. }
  1739. fclose(fp);
  1740. /*
  1741. if(txProfile.ChargingProfileId != -1)
  1742. {
  1743. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1744. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1745. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1746. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1747. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1748. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1749. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1750. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1751. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1752. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1753. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1754. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1755. {
  1756. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1757. {
  1758. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1759. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1760. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1761. }
  1762. }
  1763. }
  1764. else
  1765. DEBUG_INFO("TxProfile not found.\n");*/
  1766. }
  1767. // Search default tx profile
  1768. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1769. if((access(profileFileName, F_OK))==-1)
  1770. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1771. if((access(profileFileName, F_OK))!=-1)
  1772. {
  1773. fp = fopen(profileFileName, "r");
  1774. while(getline(&line, &len, fp) != -1)
  1775. {
  1776. json_object *obj = NULL;
  1777. obj = json_tokener_parse(line);
  1778. if(is_error(obj))
  1779. {
  1780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1781. }
  1782. else
  1783. {
  1784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1786. )
  1787. {
  1788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1790. )
  1791. {
  1792. struct tm tmFrom, tmTo;
  1793. struct timeb tbFrom, tbTo;
  1794. 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) &&
  1795. (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))
  1796. {
  1797. tmFrom.tm_year -= 1900;
  1798. tmFrom.tm_mon -= 1;
  1799. tbFrom.time = mktime(&tmFrom);
  1800. tmTo.tm_year -= 1900;
  1801. tmTo.tm_mon -= 1;
  1802. tbTo.time = mktime(&tmTo);
  1803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1804. {
  1805. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1806. {
  1807. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1809. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1810. }
  1811. defaultTxProfile.ChargingProfileId = -1;
  1812. defaultTxProfile.StackLevel = -1;
  1813. if(defaultTxProfile.ChargingProfileId == -1)
  1814. DEBUG_INFO("TxDefaultProfile found.\n");
  1815. else
  1816. DEBUG_INFO("TxDefaultProfile updated.\n");
  1817. // Required item
  1818. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1819. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1820. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1821. if(isUnitA)
  1822. {
  1823. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1824. 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++)
  1825. {
  1826. 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"));
  1827. 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?
  1828. 3:
  1829. 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")));
  1830. 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")));
  1831. }
  1832. }
  1833. else
  1834. {
  1835. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1836. 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++)
  1837. {
  1838. 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"));
  1839. 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?
  1840. 3:
  1841. 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")));
  1842. 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));
  1843. }
  1844. }
  1845. // Optional item
  1846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1847. {
  1848. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1849. }
  1850. else
  1851. {
  1852. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1853. }
  1854. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1855. {
  1856. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1857. }
  1858. else
  1859. {
  1860. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1861. }
  1862. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1863. {
  1864. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1865. }
  1866. else
  1867. {
  1868. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1869. }
  1870. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1871. {
  1872. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1873. }
  1874. else
  1875. {
  1876. defaultTxProfile.TransactionId = -1;
  1877. }
  1878. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1879. {
  1880. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1881. }
  1882. else
  1883. {
  1884. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1885. }
  1886. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1887. {
  1888. 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")));
  1889. }
  1890. else
  1891. {
  1892. 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));
  1893. }
  1894. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1895. {
  1896. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1897. }
  1898. else
  1899. {
  1900. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1901. }
  1902. }
  1903. }
  1904. }
  1905. else
  1906. {
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1912. }
  1913. defaultTxProfile.ChargingProfileId = -1;
  1914. defaultTxProfile.StackLevel = -1;
  1915. if(defaultTxProfile.ChargingProfileId == -1)
  1916. DEBUG_INFO("TxDefaultProfile found.\n");
  1917. else
  1918. DEBUG_INFO("TxDefaultProfile updated.\n");
  1919. // Required item
  1920. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1921. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1922. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1923. if(isUnitA)
  1924. {
  1925. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1926. 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++)
  1927. {
  1928. 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"));
  1929. 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?
  1930. 3:
  1931. 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")));
  1932. 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")));
  1933. }
  1934. }
  1935. else
  1936. {
  1937. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1938. 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++)
  1939. {
  1940. 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"));
  1941. 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?
  1942. 3:
  1943. 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")));
  1944. 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));
  1945. }
  1946. }
  1947. // Optional item
  1948. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1949. {
  1950. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1951. }
  1952. else
  1953. {
  1954. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1955. }
  1956. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1957. {
  1958. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1959. }
  1960. else
  1961. {
  1962. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1963. }
  1964. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1965. {
  1966. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1967. }
  1968. else
  1969. {
  1970. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1971. }
  1972. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1973. {
  1974. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1975. }
  1976. else
  1977. {
  1978. defaultTxProfile.TransactionId = -1;
  1979. }
  1980. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1983. }
  1984. else
  1985. {
  1986. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1987. }
  1988. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1989. {
  1990. 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")));
  1991. }
  1992. else
  1993. {
  1994. 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));
  1995. }
  1996. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1997. {
  1998. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1999. }
  2000. else
  2001. {
  2002. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2003. }
  2004. }
  2005. }
  2006. }
  2007. json_object_put(obj);
  2008. }
  2009. fclose(fp);
  2010. /*
  2011. if(defaultTxProfile.ChargingProfileId != -1)
  2012. {
  2013. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2014. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2015. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2016. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2017. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2018. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2019. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2020. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2021. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2022. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2023. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2024. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2025. {
  2026. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2027. {
  2028. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2029. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2030. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2031. }
  2032. }
  2033. }
  2034. else
  2035. DEBUG_INFO("TxDefaultProfile not found.\n");
  2036. DEBUG_INFO("------------------------------------\n");*/
  2037. }
  2038. // Search max profile
  2039. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2040. if((access(profileFileName, F_OK))!=-1)
  2041. {
  2042. fp = fopen(profileFileName, "r");
  2043. while(getline(&line, &len, fp) != -1)
  2044. {
  2045. json_object *obj = NULL;
  2046. obj = json_tokener_parse(line);
  2047. if(is_error(obj))
  2048. {
  2049. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2050. }
  2051. else
  2052. {
  2053. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2054. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2055. )
  2056. {
  2057. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2058. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2059. )
  2060. {
  2061. struct tm tmFrom, tmTo;
  2062. struct timeb tbFrom, tbTo;
  2063. 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) &&
  2064. (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))
  2065. {
  2066. tmFrom.tm_year -= 1900;
  2067. tmFrom.tm_mon -= 1;
  2068. tbFrom.time = mktime(&tmFrom);
  2069. tmTo.tm_year -= 1900;
  2070. tmTo.tm_mon -= 1;
  2071. tbTo.time = mktime(&tmTo);
  2072. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2073. {
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2079. }
  2080. maxProfile.ChargingProfileId = -1;
  2081. maxProfile.StackLevel = -1;
  2082. if(maxProfile.ChargingProfileId == -1)
  2083. DEBUG_INFO("MaxProfile found.\n");
  2084. else
  2085. DEBUG_INFO("MaxProfile updated.\n");
  2086. // Required item
  2087. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2088. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2089. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2090. if(isUnitA)
  2091. {
  2092. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2093. 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++)
  2094. {
  2095. 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"));
  2096. 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?
  2097. 3:
  2098. 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")));
  2099. 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")));
  2100. }
  2101. }
  2102. else
  2103. {
  2104. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2105. 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++)
  2106. {
  2107. 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"));
  2108. 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?
  2109. 3:
  2110. 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")));
  2111. 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));
  2112. }
  2113. }
  2114. // Optional item
  2115. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2116. {
  2117. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2118. }
  2119. else
  2120. {
  2121. sprintf((char*)maxProfile.ValidFrom, " ");
  2122. }
  2123. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2124. {
  2125. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2126. }
  2127. else
  2128. {
  2129. sprintf((char*)maxProfile.ValidTo, " ");
  2130. }
  2131. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2132. {
  2133. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2134. }
  2135. else
  2136. {
  2137. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2138. }
  2139. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2140. {
  2141. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2142. }
  2143. else
  2144. {
  2145. maxProfile.TransactionId = -1;
  2146. }
  2147. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2148. {
  2149. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2150. }
  2151. else
  2152. {
  2153. maxProfile.ChargingSchedule.Duration = 86400;
  2154. }
  2155. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2156. {
  2157. 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")));
  2158. }
  2159. else
  2160. {
  2161. 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));
  2162. }
  2163. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2164. {
  2165. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2166. }
  2167. else
  2168. {
  2169. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2170. }
  2171. }
  2172. }
  2173. }
  2174. else
  2175. {
  2176. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2177. {
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2181. }
  2182. maxProfile.ChargingProfileId = -1;
  2183. maxProfile.StackLevel = -1;
  2184. if(maxProfile.ChargingProfileId == -1)
  2185. DEBUG_INFO("MaxProfile found.\n");
  2186. else
  2187. DEBUG_INFO("MaxProfile updated.\n");
  2188. // Required item
  2189. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2190. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2191. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2192. if(isUnitA)
  2193. {
  2194. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2195. 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++)
  2196. {
  2197. 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"));
  2198. 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?
  2199. 3:
  2200. 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")));
  2201. 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")));
  2202. }
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2207. 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++)
  2208. {
  2209. 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"));
  2210. 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?
  2211. 3:
  2212. 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")));
  2213. 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));
  2214. }
  2215. }
  2216. // Optional item
  2217. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2218. {
  2219. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2220. }
  2221. else
  2222. {
  2223. sprintf((char*)maxProfile.ValidFrom, " ");
  2224. }
  2225. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2226. {
  2227. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2228. }
  2229. else
  2230. {
  2231. sprintf((char*)maxProfile.ValidTo, " ");
  2232. }
  2233. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2234. {
  2235. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2236. }
  2237. else
  2238. {
  2239. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2240. }
  2241. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2242. {
  2243. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2244. }
  2245. else
  2246. {
  2247. maxProfile.TransactionId = -1;
  2248. }
  2249. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2250. {
  2251. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2252. }
  2253. else
  2254. {
  2255. maxProfile.ChargingSchedule.Duration = 86400;
  2256. }
  2257. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2258. {
  2259. 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")));
  2260. }
  2261. else
  2262. {
  2263. 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));
  2264. }
  2265. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2266. {
  2267. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2268. }
  2269. else
  2270. {
  2271. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2272. }
  2273. }
  2274. }
  2275. }
  2276. json_object_put(obj);
  2277. }
  2278. fclose(fp);
  2279. /*
  2280. if(maxProfile.ChargingProfileId !=-1)
  2281. {
  2282. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2283. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2284. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2285. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2286. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2287. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2288. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2289. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2290. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2291. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2292. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2296. {
  2297. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2298. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2299. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2300. }
  2301. }
  2302. }
  2303. else
  2304. DEBUG_INFO("MaxProfile not found.\n");
  2305. DEBUG_INFO("------------------------------------\n");*/
  2306. }
  2307. /*
  2308. * Align found profile start schedule & periods
  2309. */
  2310. //DEBUG_INFO("====================================\n");
  2311. /*
  2312. // For local test usage, force modify found profile start schedule info
  2313. 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);
  2314. 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);
  2315. 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);
  2316. */
  2317. if(txProfile.ChargingProfileId != -1)
  2318. {
  2319. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2320. {
  2321. if(txProfile.ChargingSchedule.Duration != -1)
  2322. {
  2323. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2324. 0:
  2325. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2326. }
  2327. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2328. {
  2329. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2330. {
  2331. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2332. 0:
  2333. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2334. if(idxPeriod > 0)
  2335. {
  2336. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2337. {
  2338. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2345. {
  2346. if(txProfile.ChargingSchedule.Duration != -1)
  2347. {
  2348. 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?
  2349. 0:
  2350. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2351. }
  2352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2353. {
  2354. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2355. {
  2356. 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?
  2357. 0:
  2358. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2359. if(idxPeriod > 0)
  2360. {
  2361. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2362. {
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2364. }
  2365. }
  2366. }
  2367. }
  2368. }
  2369. else
  2370. {
  2371. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2372. {
  2373. if(txProfile.ChargingSchedule.Duration != -1)
  2374. {
  2375. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2376. 0:
  2377. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2378. }
  2379. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2380. {
  2381. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2382. {
  2383. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2384. 0:
  2385. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2386. if(idxPeriod > 0)
  2387. {
  2388. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2389. {
  2390. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396. else
  2397. {
  2398. if(txProfile.ChargingSchedule.Duration != -1)
  2399. {
  2400. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2401. 0:
  2402. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2403. }
  2404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2405. {
  2406. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2407. {
  2408. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2409. 0:
  2410. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2411. if(idxPeriod > 0)
  2412. {
  2413. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2414. {
  2415. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. /*
  2423. DEBUG_INFO("txProfile after align.\n");
  2424. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2425. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2426. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2427. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2428. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2429. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2430. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2431. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2432. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2433. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2434. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2436. {
  2437. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2438. {
  2439. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2440. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2441. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2442. }
  2443. }*/
  2444. }
  2445. if(defaultTxProfile.ChargingProfileId != -1)
  2446. {
  2447. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2448. {
  2449. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2450. {
  2451. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2452. 0:
  2453. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2454. }
  2455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2456. {
  2457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2458. {
  2459. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2460. 0:
  2461. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2462. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2463. {
  2464. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2465. }
  2466. if(idxPeriod > 0)
  2467. {
  2468. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2469. {
  2470. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2471. }
  2472. }
  2473. }
  2474. }
  2475. }
  2476. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2477. {
  2478. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2479. {
  2480. 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?
  2481. 0:
  2482. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2483. }
  2484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2485. {
  2486. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2487. {
  2488. 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?
  2489. 0:
  2490. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2491. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2492. {
  2493. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2494. }
  2495. if(idxPeriod > 0)
  2496. {
  2497. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2498. {
  2499. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. else
  2506. {
  2507. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2508. {
  2509. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2510. {
  2511. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2512. 0:
  2513. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2514. }
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2518. {
  2519. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2520. 0:
  2521. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2522. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2523. {
  2524. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2525. }
  2526. if(idxPeriod > 0)
  2527. {
  2528. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2529. {
  2530. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2531. }
  2532. }
  2533. }
  2534. }
  2535. }
  2536. else
  2537. {
  2538. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2539. {
  2540. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2541. 0:
  2542. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2543. }
  2544. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2545. {
  2546. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2547. {
  2548. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2549. 0:
  2550. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2552. {
  2553. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. }
  2555. if(idxPeriod > 0)
  2556. {
  2557. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2558. {
  2559. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. /*
  2567. DEBUG_INFO("defaultTxProfile after align.\n");
  2568. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2569. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2570. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2571. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2572. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2573. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2574. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2575. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2576. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2577. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2578. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2580. {
  2581. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2582. {
  2583. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2584. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2585. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2586. }
  2587. }
  2588. DEBUG_INFO("------------------------------------\n");*/
  2589. }
  2590. if(maxProfile.ChargingProfileId != -1)
  2591. {
  2592. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2593. {
  2594. if(maxProfile.ChargingSchedule.Duration != -1)
  2595. {
  2596. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2597. 0:
  2598. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2599. }
  2600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2601. {
  2602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2603. {
  2604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2605. 0:
  2606. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2607. if(idxPeriod > 0)
  2608. {
  2609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2610. {
  2611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2618. {
  2619. if(maxProfile.ChargingSchedule.Duration != -1)
  2620. {
  2621. 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?
  2622. 0:
  2623. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2624. }
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2628. {
  2629. 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?
  2630. 0:
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2632. if(idxPeriod > 0)
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2635. {
  2636. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. else
  2643. {
  2644. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2645. {
  2646. if(maxProfile.ChargingSchedule.Duration != -1)
  2647. {
  2648. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2649. 0:
  2650. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2651. }
  2652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2653. {
  2654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2655. {
  2656. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2657. 0:
  2658. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2659. if(idxPeriod > 0)
  2660. {
  2661. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2662. {
  2663. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2664. }
  2665. }
  2666. }
  2667. }
  2668. }
  2669. else
  2670. {
  2671. if(maxProfile.ChargingSchedule.Duration != -1)
  2672. {
  2673. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2674. 0:
  2675. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2676. }
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2680. {
  2681. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2682. 0:
  2683. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2684. if(idxPeriod > 0)
  2685. {
  2686. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2687. {
  2688. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. /*
  2696. DEBUG_INFO("MaxProfile after align.\n");
  2697. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2698. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2699. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2700. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2701. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2702. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2703. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2704. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2705. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2706. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2707. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2709. {
  2710. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2711. {
  2712. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2713. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2714. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2715. }
  2716. }
  2717. DEBUG_INFO("------------------------------------\n");*/
  2718. }
  2719. /*
  2720. * Merge to conposite schedule
  2721. */
  2722. //DEBUG_INFO("====================================\n");
  2723. // Find each profile period quantity
  2724. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2725. {
  2726. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2727. limitMax = idx+1;
  2728. }
  2729. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2730. {
  2731. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2732. limitDef = idx+1;
  2733. }
  2734. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2735. {
  2736. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2737. limitTx = idx+1;
  2738. }
  2739. // TxProfile found, composite schedule based on it
  2740. if(txProfile.ChargingProfileId != -1)
  2741. {
  2742. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2743. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2744. {
  2745. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2746. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2747. (txProfile.ChargingSchedule.Duration > 0))
  2748. {
  2749. if(maxProfile.ChargingProfileId != -1)
  2750. {
  2751. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2752. {
  2753. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2754. {
  2755. if((maxProfile.ChargingSchedule.Duration > 0))
  2756. {
  2757. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2758. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2759. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2760. }
  2761. else
  2762. {
  2763. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2764. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2765. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2766. }
  2767. }
  2768. if(idxMaxPeriod == (limitMax-1))
  2769. {
  2770. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2771. {
  2772. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2773. {
  2774. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2775. compositePeriodIdx++;
  2776. }
  2777. else
  2778. {
  2779. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2780. }
  2781. }
  2782. }
  2783. }
  2784. }
  2785. else
  2786. {
  2787. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2788. {
  2789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2790. compositePeriodIdx++;
  2791. }
  2792. else
  2793. {
  2794. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2795. }
  2796. }
  2797. }
  2798. if(idxTxPeriod == (limitTx-1))
  2799. {
  2800. if(defaultTxProfile.ChargingProfileId != -1)
  2801. {
  2802. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2803. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2804. {
  2805. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2806. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2807. (defaultTxProfile.ChargingSchedule.Duration>0))
  2808. {
  2809. if(maxProfile.ChargingProfileId != -1)
  2810. {
  2811. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2812. {
  2813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2814. {
  2815. if((maxProfile.ChargingSchedule.Duration > 0))
  2816. {
  2817. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2818. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2819. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2820. }
  2821. else
  2822. {
  2823. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2824. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2825. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2826. }
  2827. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2828. {
  2829. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2830. {
  2831. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2832. compositePeriodIdx++;
  2833. }
  2834. else
  2835. {
  2836. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2837. }
  2838. }
  2839. // Delete duplicate period
  2840. if(compositePeriodIdx > 1)
  2841. {
  2842. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2843. {
  2844. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2845. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2846. compositePeriodIdx -= 1;
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2853. {
  2854. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2855. compositePeriodIdx++;
  2856. }
  2857. else
  2858. {
  2859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2860. }
  2861. break;
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2868. {
  2869. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2870. compositePeriodIdx++;
  2871. }
  2872. else
  2873. {
  2874. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. }
  2883. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2884. else if(defaultTxProfile.ChargingProfileId != -1)
  2885. {
  2886. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2887. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2888. {
  2889. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2890. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2891. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2892. {
  2893. if(maxProfile.ChargingProfileId != -1)
  2894. {
  2895. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2896. {
  2897. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2898. {
  2899. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2900. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2901. if((maxProfile.ChargingSchedule.Duration > 0))
  2902. {
  2903. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2904. }
  2905. else
  2906. {
  2907. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2908. }
  2909. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2910. {
  2911. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2912. {
  2913. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2914. compositePeriodIdx++;
  2915. }
  2916. else
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2919. }
  2920. }
  2921. // Delete duplicate period
  2922. if(compositePeriodIdx > 1)
  2923. {
  2924. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2925. {
  2926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2928. compositePeriodIdx -= 1;
  2929. }
  2930. }
  2931. }
  2932. else
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2935. {
  2936. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2937. compositePeriodIdx++;
  2938. }
  2939. else
  2940. {
  2941. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2942. }
  2943. break;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2950. {
  2951. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2952. compositePeriodIdx++;
  2953. }
  2954. else
  2955. {
  2956. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2957. }
  2958. }
  2959. }
  2960. }
  2961. }
  2962. // Fill other period by MaxProfile
  2963. if(maxProfile.ChargingProfileId != -1)
  2964. {
  2965. if(compositePeriodIdx==0)
  2966. {
  2967. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2968. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2969. {
  2970. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2971. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2972. (maxProfile.ChargingSchedule.Duration > 0))
  2973. {
  2974. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2975. {
  2976. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2977. compositePeriodIdx++;
  2978. }
  2979. else
  2980. {
  2981. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2982. }
  2983. }
  2984. }
  2985. }
  2986. else
  2987. {
  2988. int lastCompositePeriodIdx = compositePeriodIdx;
  2989. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2990. {
  2991. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2992. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2993. (maxProfile.ChargingSchedule.Duration > 0))
  2994. {
  2995. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2996. {
  2997. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2998. {
  2999. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3000. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3001. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3002. }
  3003. else
  3004. {
  3005. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3006. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3007. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3008. }
  3009. }
  3010. if(tmpPeriod.Limit != -1)
  3011. {
  3012. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3013. {
  3014. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3015. {
  3016. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3017. compositePeriodIdx++;
  3018. }
  3019. else
  3020. {
  3021. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3022. }
  3023. }
  3024. // Delete duplicate period
  3025. if(compositePeriodIdx > 1)
  3026. {
  3027. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3028. {
  3029. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3030. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3031. compositePeriodIdx -= 1;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. compositeProfile->ChargingSchedule.Duration = durationReq;
  3040. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3041. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3042. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3043. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3044. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3045. {
  3046. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3047. {
  3048. compositeProfile->ChargingProfileId = 1;
  3049. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3050. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3051. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3052. }
  3053. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3054. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3055. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3056. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3057. }
  3058. if(line)
  3059. free(line);
  3060. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3061. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3062. }
  3063. //==========================================
  3064. // Init all share memory
  3065. //==========================================
  3066. int InitShareMemory()
  3067. {
  3068. int result = PASS;
  3069. int MeterSMId;
  3070. //creat ShmSysConfigAndInfo
  3071. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3072. {
  3073. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3074. result = FAIL;
  3075. }
  3076. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3077. {
  3078. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3079. result = FAIL;
  3080. }
  3081. else
  3082. {}
  3083. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3084. {
  3085. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3086. result = FAIL;
  3087. }
  3088. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3089. {
  3090. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3091. result = FAIL;
  3092. }
  3093. else
  3094. {}
  3095. //creat ShmPsuData
  3096. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3097. {
  3098. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3099. result = FAIL;
  3100. }
  3101. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3102. {
  3103. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3104. result = FAIL;
  3105. }
  3106. else
  3107. {}
  3108. //link ShmOCPP16Data
  3109. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3110. {
  3111. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3112. result = FAIL;
  3113. }
  3114. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3115. {
  3116. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3117. result = FAIL;
  3118. }
  3119. else
  3120. {}
  3121. //creat ShmOCPP16DataPH
  3122. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3123. {
  3124. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3125. result = FAIL;
  3126. }
  3127. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3128. {
  3129. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3130. result = FAIL;
  3131. }
  3132. else
  3133. {}
  3134. /****************************** For Initial Settings************************************************/
  3135. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3136. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3137. // allocate Configuration memory address
  3138. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3139. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3140. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3141. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3142. //offline MeterValue Interval
  3143. TempMeterValueInterval = 0;
  3144. return result;
  3145. }
  3146. int ProcessShareMemory()
  3147. {
  3148. int result = PASS;
  3149. if(InitShareMemory() == FAIL)
  3150. {
  3151. DEBUG_ERROR("InitShareMemory NG\n");
  3152. if(ShmStatusCodeData!=NULL)
  3153. {
  3154. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3155. }
  3156. result = FAIL;
  3157. }
  3158. // Model name parsing
  3159. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3160. {
  3161. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3162. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3163. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3164. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3166. ) // 'D' means DC
  3167. {
  3168. // DO series
  3169. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3170. {
  3171. SystemInitial += 1;
  3172. gunTotalNumber += 1;
  3173. gunType[gun_index] = GUN_TYPE_DO;
  3174. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3175. {
  3176. case Gun_Type_Chademo:
  3177. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3178. break;
  3179. case Gun_Type_CCS_2:
  3180. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3181. break;
  3182. case Gun_Type_GB:
  3183. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3184. break;
  3185. case Gun_Type_AC:
  3186. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3187. break;
  3188. default:
  3189. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3190. break;
  3191. }
  3192. }
  3193. }
  3194. else
  3195. {
  3196. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3197. {
  3198. SystemInitial += 1;
  3199. gunTotalNumber += 1;
  3200. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3201. {
  3202. case Gun_Type_Chademo:
  3203. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3204. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3205. break;
  3206. case Gun_Type_CCS_2:
  3207. gunType[gun_index] = GUN_TYPE_CCS;
  3208. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3209. break;
  3210. case Gun_Type_GB:
  3211. gunType[gun_index] = GUN_TYPE_GBT;
  3212. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3213. break;
  3214. case Gun_Type_AC:
  3215. gunType[gun_index] = GUN_TYPE_AC;
  3216. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3217. break;
  3218. default:
  3219. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3220. break;
  3221. }
  3222. }
  3223. }
  3224. }
  3225. else
  3226. {
  3227. DEBUG_ERROR("Model name parsing fail.\n");
  3228. result = FAIL;
  3229. }
  3230. if(result != PASS)sleep(5);
  3231. return result;
  3232. }
  3233. void checkRemoteStart(uint8_t connectorIdInt)
  3234. {
  3235. uint8_t tempIndex;
  3236. int result = PASS;
  3237. char cmdBuf[512];
  3238. //check Transaction active
  3239. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3240. {
  3241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3242. {
  3243. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3244. }
  3245. else
  3246. {
  3247. tempIndex = connectorIdInt -1;
  3248. }
  3249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3250. {
  3251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3252. {
  3253. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3254. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3255. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3256. {
  3257. //Reserved
  3258. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3259. }
  3260. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3261. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3262. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3263. {
  3264. //Reserved
  3265. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3266. result = FAIL;
  3267. goto end;
  3268. }
  3269. else
  3270. {
  3271. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3272. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3273. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3274. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3275. {
  3276. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3277. result = FAIL;
  3278. goto end;
  3279. }
  3280. }//END FOR ELSE
  3281. }
  3282. }// END FOR CHAdeMO_QUANTITY
  3283. }
  3284. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3285. {
  3286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3287. {
  3288. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3289. }
  3290. else
  3291. {
  3292. tempIndex = connectorIdInt -1;
  3293. }
  3294. for (int index = 0; index < CCS_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3297. {
  3298. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3300. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3301. {
  3302. //Reserved
  3303. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3304. }
  3305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3307. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3308. {
  3309. //Reserved
  3310. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3311. result = FAIL;
  3312. goto end;
  3313. }
  3314. else
  3315. {
  3316. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3317. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3318. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3319. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3320. {
  3321. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3322. result = FAIL;
  3323. goto end;
  3324. }
  3325. }// END FOR ELSE
  3326. }
  3327. }// END FOR CCS_QUANTITY
  3328. }
  3329. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3330. {
  3331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3332. {
  3333. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3334. }
  3335. else
  3336. {
  3337. tempIndex = connectorIdInt -1;
  3338. }
  3339. for (int index = 0; index < GB_QUANTITY; index++)
  3340. {
  3341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3342. {
  3343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3344. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3345. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3346. {
  3347. //Reserved
  3348. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3349. }
  3350. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3351. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3352. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3353. {
  3354. //Reserved
  3355. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3356. result = FAIL;
  3357. goto end;
  3358. }
  3359. else
  3360. {
  3361. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3362. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3363. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3364. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3365. {
  3366. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3367. result = FAIL;
  3368. goto end;
  3369. }
  3370. }// END FOR ELSE
  3371. }
  3372. } // END FOR GB_QUANTITY
  3373. }
  3374. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3375. {
  3376. tempIndex = connectorIdInt -1;
  3377. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3380. {
  3381. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3382. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3383. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3384. {
  3385. //Reserved
  3386. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3387. }
  3388. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3389. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3390. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3391. {
  3392. //Reserved
  3393. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3394. result = FAIL;
  3395. goto end;
  3396. }
  3397. else
  3398. {
  3399. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3400. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3401. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3402. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3403. {
  3404. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3405. result = FAIL;
  3406. goto end;
  3407. }
  3408. }// END FOR ELSE
  3409. }
  3410. } // END FOR GB_QUANTITY
  3411. }
  3412. else
  3413. {
  3414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3415. {
  3416. tempIndex = 2;
  3417. }
  3418. else
  3419. {
  3420. tempIndex = connectorIdInt -1;
  3421. }
  3422. for (int index = 0; index < AC_QUANTITY; index++)
  3423. {
  3424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3425. {
  3426. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3427. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3428. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3429. {
  3430. //Reserved
  3431. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3432. }
  3433. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3434. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3435. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3436. {
  3437. //Reserved
  3438. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3439. result = FAIL;
  3440. goto end;
  3441. }
  3442. else
  3443. {
  3444. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3445. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3446. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3447. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3448. {
  3449. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3450. result = FAIL;
  3451. goto end;
  3452. }
  3453. }//END FOR ELSE
  3454. }
  3455. }// END FOR AC_QUANTITY
  3456. }
  3457. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3458. {
  3459. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3460. {
  3461. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3462. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3463. {
  3464. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3465. system(cmdBuf);
  3466. }
  3467. }
  3468. else
  3469. {
  3470. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3471. result = FAIL;
  3472. }
  3473. }
  3474. end:
  3475. if(result == PASS)
  3476. {
  3477. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3478. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3479. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3480. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3482. }
  3483. }
  3484. void CheckSystemValue(void)
  3485. {
  3486. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3487. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3488. char filenmae[100]={0};
  3489. char str[100]={0};
  3490. int tempIndex = 0;
  3491. //===============================
  3492. // send Heartbeat
  3493. //===============================
  3494. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3495. {
  3496. //parameter for test
  3497. sendHeartbeatRequest(0);
  3498. //==============================================
  3499. // Reset Waiting Time
  3500. //==============================================
  3501. HeartBeatWithNOResponse += 2;
  3502. }
  3503. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3504. {
  3505. //==========================================
  3506. // Check remote start without connector id
  3507. //==========================================
  3508. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3509. {
  3510. int connectorIdInt = -1;
  3511. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3512. {
  3513. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3514. {
  3515. connectorIdInt = (gun_index+1);
  3516. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3517. checkRemoteStart(connectorIdInt);
  3518. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3519. break;
  3520. }
  3521. }
  3522. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3523. {
  3524. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3525. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3526. }
  3527. }
  3528. //==========================================
  3529. // csu trigger DataTransferReq
  3530. //==========================================
  3531. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3532. {
  3533. sendDataTransferRequest(gun_index);
  3534. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3535. }
  3536. //===============================
  3537. // CSU Trigger Authorize Request
  3538. //===============================
  3539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3540. {
  3541. sendAuthorizeRequest(0);
  3542. authorizeRetryTimes = authorizeRetryTimes + 1;
  3543. if(authorizeRetryTimes < 3)
  3544. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3545. }
  3546. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3547. {
  3548. authorizeRetryTimes = 0;
  3549. SetOcppConnStatus(FALSE);
  3550. server_sign = FALSE;
  3551. }
  3552. 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))
  3553. {
  3554. sendAuthorizeRequest(0);
  3555. }
  3556. //==============================================
  3557. // Charger start transaction
  3558. //==============================================
  3559. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3560. {
  3561. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3562. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3563. sendStartTransactionRequest(gun_index);
  3564. refreshStartTimer(&clientTime.StartTransaction);
  3565. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3566. //storeTempStopTransaction(gun_index);
  3567. }
  3568. //==============================================
  3569. // Charger stop transaction
  3570. //==============================================
  3571. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3572. {
  3573. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3574. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3575. sendStopTransactionRequest(gun_index);
  3576. refreshStartTimer(&clientTime.StopTransaction);
  3577. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3578. }
  3579. //==============================================
  3580. // Charger status report
  3581. //==============================================
  3582. //--- Check Mode Change ---//
  3583. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3584. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3587. {
  3588. tempIndex = ((gun_index==2) ? 1: 0);
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3597. {
  3598. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3599. {
  3600. // Sent unplug message for California pricing logic
  3601. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3602. {
  3603. uint8_t ts[20];
  3604. getNowDatetime(ts);
  3605. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3606. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3607. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3608. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3609. }
  3610. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3611. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3612. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3613. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3614. {
  3615. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3616. if((access(filenmae,F_OK))!=-1)
  3617. {
  3618. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3619. sprintf(str,"rm -f %s",filenmae);
  3620. system(str);
  3621. }
  3622. }
  3623. }
  3624. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3625. #if 1 // for TempStopTransaction
  3626. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3627. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3628. {
  3629. checkTempStopTransaction(gun_index);
  3630. }
  3631. #endif
  3632. }
  3633. }
  3634. }
  3635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3636. {
  3637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3638. {
  3639. tempIndex = ((gun_index==2) ? 1: 0);
  3640. }
  3641. else
  3642. {
  3643. tempIndex = gun_index;
  3644. }
  3645. for (int index = 0; index < CCS_QUANTITY; index++)
  3646. {
  3647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3648. {
  3649. 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]*/ )
  3650. {
  3651. // Sent unplug message for California pricing logic
  3652. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3653. {
  3654. uint8_t ts[20];
  3655. getNowDatetime(ts);
  3656. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3657. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3658. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3659. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3660. }
  3661. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3662. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3663. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3664. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3665. {
  3666. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3667. if((access(filenmae,F_OK))!=-1)
  3668. {
  3669. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3670. sprintf(str,"rm -f %s",filenmae);
  3671. system(str);
  3672. }
  3673. }
  3674. }
  3675. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3676. #if 1 // for TempStopTransaction
  3677. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3678. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3679. {
  3680. checkTempStopTransaction(gun_index);
  3681. }
  3682. #endif
  3683. }
  3684. }
  3685. }
  3686. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < GB_QUANTITY; index++)
  3697. {
  3698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3699. {
  3700. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3701. {
  3702. // Sent unplug message for California pricing logic
  3703. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3704. {
  3705. uint8_t ts[20];
  3706. getNowDatetime(ts);
  3707. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3710. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3711. }
  3712. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3713. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3714. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3715. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3716. {
  3717. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3718. if((access(filenmae,F_OK))!=-1)
  3719. {
  3720. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3721. sprintf(str,"rm -f %s",filenmae);
  3722. system(str);
  3723. }
  3724. }
  3725. }
  3726. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3727. #if 1 // for TempStopTransaction
  3728. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3729. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3730. {
  3731. checkTempStopTransaction(gun_index);
  3732. }
  3733. #endif
  3734. }
  3735. }
  3736. }
  3737. else if(gunType[gun_index] == GUN_TYPE_DO)
  3738. {
  3739. tempIndex = gun_index;
  3740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3741. {
  3742. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3743. {
  3744. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3745. {
  3746. // Sent unplug message for California pricing logic
  3747. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3748. {
  3749. uint8_t ts[20];
  3750. getNowDatetime(ts);
  3751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3754. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3755. }
  3756. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3757. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3758. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3759. 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
  3760. {
  3761. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3762. if((access(filenmae,F_OK))!=-1)
  3763. {
  3764. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3765. sprintf(str,"rm -f %s",filenmae);
  3766. system(str);
  3767. }
  3768. }
  3769. }
  3770. 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);
  3771. #if 1 // for TempStopTransaction
  3772. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3773. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3774. {
  3775. checkTempStopTransaction(gun_index);
  3776. }
  3777. #endif
  3778. }
  3779. }
  3780. }
  3781. else
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3784. {
  3785. tempIndex = 2;
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < AC_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3794. {
  3795. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3796. {
  3797. // Sent unplug message for California pricing logic
  3798. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3799. {
  3800. uint8_t ts[20];
  3801. getNowDatetime(ts);
  3802. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3803. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3804. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3805. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3806. }
  3807. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3808. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3809. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3810. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3811. {
  3812. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3813. if((access(filenmae,F_OK))!=-1)
  3814. {
  3815. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3816. sprintf(str,"rm -f %s",filenmae);
  3817. system(str);
  3818. }
  3819. }
  3820. }
  3821. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3822. #if 1 // for TempStopTransaction
  3823. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3824. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3825. {
  3826. checkTempStopTransaction(gun_index);
  3827. }
  3828. #endif
  3829. }
  3830. }// END
  3831. }
  3832. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  3833. (
  3834. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3835. )
  3836. )
  3837. {
  3838. if(SystemInitial > 0)
  3839. SystemInitial -= 1;
  3840. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3841. sendStatusNotificationRequest(gun_index);
  3842. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3843. }
  3844. //==============================================
  3845. // CSU Trigger Smart Charging Profilw
  3846. //==============================================
  3847. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3848. {
  3849. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3850. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3851. }
  3852. //==============================================
  3853. // Meter report
  3854. //==============================================
  3855. // Trigger MeterValue
  3856. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3857. {
  3858. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3859. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3860. }
  3861. // ClockAlign MeterValue
  3862. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3863. {
  3864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3865. {
  3866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3867. {
  3868. tempIndex = ((gun_index==2) ? 1: 0);
  3869. }
  3870. else
  3871. {
  3872. tempIndex = gun_index;
  3873. }
  3874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3875. {
  3876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3877. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3878. {
  3879. reqClockAlignMeter[gun_index] = 1;
  3880. }
  3881. }// End for CHAdeMO
  3882. }
  3883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3884. {
  3885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3886. {
  3887. tempIndex = ((gun_index==2) ? 1: 0);
  3888. }
  3889. else
  3890. {
  3891. tempIndex = gun_index;
  3892. }
  3893. for (int index = 0; index < CCS_QUANTITY; index++)
  3894. {
  3895. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3896. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3897. {
  3898. reqClockAlignMeter[gun_index] = 1;
  3899. }
  3900. } // End for CCS
  3901. }
  3902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3903. {
  3904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3905. {
  3906. tempIndex = ((gun_index==2) ? 1: 0);
  3907. }
  3908. else
  3909. {
  3910. tempIndex = gun_index;
  3911. }
  3912. for (int index = 0; index < GB_QUANTITY; index++)
  3913. {
  3914. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3915. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3916. {
  3917. reqClockAlignMeter[gun_index] = 1;
  3918. }
  3919. }// End for GB
  3920. }
  3921. else if(gunType[gun_index] == GUN_TYPE_DO)
  3922. {
  3923. tempIndex = gun_index;
  3924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3925. {
  3926. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3927. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3928. {
  3929. reqClockAlignMeter[gun_index] = 1;
  3930. }
  3931. }
  3932. }
  3933. else
  3934. {
  3935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3936. {
  3937. tempIndex = 2;
  3938. }
  3939. else
  3940. {
  3941. tempIndex = gun_index;
  3942. }
  3943. for (int index = 0; index < AC_QUANTITY; index++)
  3944. {
  3945. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3946. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3947. {
  3948. reqClockAlignMeter[gun_index] = 1;
  3949. }
  3950. }//End for AC
  3951. }
  3952. }
  3953. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  3954. {
  3955. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3956. reqClockAlignMeter[gun_index] = 0;
  3957. }
  3958. // Sample period MeterValue
  3959. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
  3960. {
  3961. //check Transaction active
  3962. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3965. {
  3966. tempIndex = ((gun_index==2) ? 1: 0);
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3976. {
  3977. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3978. {
  3979. reqSampleMeter[gun_index] = 1;
  3980. }
  3981. }
  3982. }// End for CHAdeMO
  3983. }
  3984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3985. {
  3986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3987. {
  3988. tempIndex = ((gun_index==2) ? 1: 0);
  3989. }
  3990. else
  3991. {
  3992. tempIndex = gun_index;
  3993. }
  3994. for (int index = 0; index < CCS_QUANTITY; index++)
  3995. {
  3996. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3997. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3998. {
  3999. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4000. {
  4001. reqSampleMeter[gun_index] = 1;
  4002. }
  4003. }
  4004. } // End for CCS
  4005. }
  4006. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4007. {
  4008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4009. {
  4010. tempIndex = ((gun_index==2) ? 1: 0);
  4011. }
  4012. else
  4013. {
  4014. tempIndex = gun_index;
  4015. }
  4016. for (int index = 0; index < GB_QUANTITY; index++)
  4017. {
  4018. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4019. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4020. {
  4021. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4022. {
  4023. reqSampleMeter[gun_index] = 1;
  4024. }
  4025. }
  4026. }// End for GB
  4027. }
  4028. else if(gunType[gun_index] == GUN_TYPE_DO)
  4029. {
  4030. tempIndex = gun_index;
  4031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4032. {
  4033. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4034. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4035. {
  4036. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4037. {
  4038. reqSampleMeter[gun_index] = 1;
  4039. }
  4040. }
  4041. }
  4042. }
  4043. else
  4044. {
  4045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4046. {
  4047. tempIndex = 2;
  4048. }
  4049. else
  4050. {
  4051. tempIndex = gun_index;
  4052. }
  4053. for (int index = 0; index < AC_QUANTITY; index++)
  4054. {
  4055. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4056. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4057. {
  4058. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4059. {
  4060. reqSampleMeter[gun_index] = 1;
  4061. }
  4062. }
  4063. }//End for AC
  4064. }
  4065. if(reqSampleMeter[gun_index] == 1)
  4066. {
  4067. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4068. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4069. //storeTempStopTransaction(gun_index);
  4070. }
  4071. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4072. }
  4073. //==============================================
  4074. // Check Connector reserved
  4075. //==============================================
  4076. //===============================
  4077. // Check if Reserve is expired
  4078. //===============================
  4079. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4080. {
  4081. double diff_t;
  4082. struct tm tp;
  4083. // current time
  4084. time_t t = time(NULL);
  4085. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4086. tp.tm_isdst = -1;
  4087. time_t utc = mktime(&tp);
  4088. diff_t = difftime(utc, t);
  4089. if(diff_t <= 0)
  4090. {
  4091. DEBUG_INFO("reserve expired.\n");
  4092. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4093. }
  4094. }//END OF Check if Reserve is expired
  4095. //==========================================
  4096. // csu trigger FirmwareStatusNotificationReq
  4097. //==========================================
  4098. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4099. {
  4100. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4101. }
  4102. //==========================================
  4103. // csu trigger DiagnosticsStatusNotificationReq
  4104. //==========================================
  4105. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4106. {
  4107. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4108. }
  4109. //==========================================
  4110. // csu trigger CancelReservationConf
  4111. //==========================================
  4112. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4113. {
  4114. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4115. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4116. }
  4117. //==========================================
  4118. // csu trigger ChangeAvailabilityConf
  4119. //==========================================
  4120. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4121. {
  4122. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4123. }
  4124. //==========================================
  4125. // csu trigger UnlockConnectorConf
  4126. //==========================================
  4127. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4128. {
  4129. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4130. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4131. }
  4132. //==========================================
  4133. // csu trigger ReserveNowConf
  4134. //==========================================
  4135. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4136. {
  4137. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4138. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4139. }
  4140. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4141. {
  4142. sendSignCertificateRequest();
  4143. }
  4144. }
  4145. }
  4146. //==========================================
  4147. // send request routine
  4148. //==========================================
  4149. int sendAuthorizeRequest(int gun_index)
  4150. {
  4151. mtrace();
  4152. int result = FAIL;
  4153. char message[100]={0};
  4154. char guid[37];
  4155. char tempdata[65]={0};
  4156. DEBUG_INFO("sendAuthorizeRequest...\n");
  4157. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4158. //Local Authorize
  4159. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4160. {
  4161. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4162. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4163. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4164. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4165. result = PASS;
  4166. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4167. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4168. authorizeRetryTimes = 0;
  4169. return result;
  4170. }
  4171. 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))||
  4172. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4173. {
  4174. // Query from cache
  4175. DEBUG_INFO("Authorize from cache.\n");
  4176. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4177. // Query from list
  4178. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4179. {
  4180. DEBUG_INFO("Authorize from list.\n");
  4181. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4182. }
  4183. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4184. {
  4185. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4186. {
  4187. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4188. }
  4189. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4190. {
  4191. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4192. }
  4193. if(!GetOcppConnStatus())
  4194. {
  4195. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4196. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4197. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4198. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4199. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4200. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4201. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4202. authorizeRetryTimes = 0;
  4203. return result;
  4204. }
  4205. }
  4206. else
  4207. {
  4208. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4209. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4210. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4211. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4212. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4213. else
  4214. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4215. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4216. result = PASS;
  4217. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4218. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4219. authorizeRetryTimes = 0;
  4220. return result;
  4221. }
  4222. }
  4223. //initialize struct Authorize
  4224. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4225. //get data from shared memory
  4226. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4227. random_uuid(guid);
  4228. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4229. LWS_Send(message);
  4230. sprintf(tempdata, "Authorize,%d", gun_index);
  4231. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4232. {
  4233. result = PASS;
  4234. DEBUG_INFO("Authorize mapItem pass\n");
  4235. }
  4236. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4237. return result;
  4238. }
  4239. int sendBootNotificationRequest(void)
  4240. {
  4241. mtrace();
  4242. int result = FAIL;
  4243. char message[500]={0}, payload[700]={0};
  4244. char guid[37]={0};
  4245. char tempdata[65]={0};
  4246. // Fill BootNotification fields
  4247. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4248. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4249. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4250. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4251. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4252. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4253. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4254. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4255. ShmOCPP16DataPH->ChargeBoxId
  4256. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4257. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4258. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4259. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4260. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4261. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4262. random_uuid(guid);
  4263. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4264. LWS_Send(message);
  4265. sprintf(tempdata, "BootNotification,0");
  4266. 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*/)
  4267. {
  4268. result = PASS;
  4269. }
  4270. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4271. strcpy(queuedata,message);
  4272. return result;
  4273. }
  4274. int sendDataTransferRequest(int gun_index)
  4275. {
  4276. mtrace();
  4277. char message[1000]={0};
  4278. char guid[37]={0};
  4279. char tempdata[65]={0};
  4280. int result = FAIL;
  4281. random_uuid(guid);
  4282. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4283. MESSAGE_TYPE_CALL,
  4284. guid,
  4285. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4286. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4287. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4288. LWS_Send(message);
  4289. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4290. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4291. {
  4292. result = PASS;
  4293. DEBUG_INFO("DataTransfer mapItem pass\n");
  4294. }
  4295. return result;
  4296. }
  4297. int sendDiagnosticsStatusNotificationRequest(char *status)
  4298. {
  4299. mtrace();
  4300. int result = FAIL;
  4301. char message[110]={0};
  4302. char guid[37]={0};
  4303. char tempdata[65]={0};
  4304. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4305. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4306. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4307. random_uuid(guid);
  4308. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4309. LWS_SendNow(message);
  4310. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4311. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4312. {
  4313. result = PASS;
  4314. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4315. }
  4316. //#ifdef SystemLogMessage
  4317. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4318. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4319. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4320. //#endif
  4321. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4322. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4323. //record status
  4324. if(strcmp(status,"Idle")==0)
  4325. {
  4326. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4327. }
  4328. else if(strcmp(status,"Uploaded")==0)
  4329. {
  4330. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4331. }
  4332. else if(strcmp(status,"UploadFailed")==0)
  4333. {
  4334. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4335. }
  4336. else if(strcmp(status,"Uploading")==0)
  4337. {
  4338. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4339. }
  4340. return result;
  4341. }
  4342. int sendFirmwareStatusNotificationRequest(char *status)
  4343. {
  4344. mtrace();
  4345. int result = FAIL;
  4346. char message[110]={0};
  4347. char guid[37]={0};
  4348. char tempdata[65]={0};
  4349. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4350. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4351. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4352. random_uuid(guid);
  4353. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4354. LWS_SendNow(message);
  4355. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4356. 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*/)
  4357. {
  4358. result = PASS;
  4359. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4360. }
  4361. //#ifdef SystemLogMessage
  4362. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4363. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4364. //#endif
  4365. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4366. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4367. //record status
  4368. if(strcmp(status,"Downloaded")==0)
  4369. {
  4370. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4371. }
  4372. else if(strcmp(status,"DownloadFailed")==0)
  4373. {
  4374. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4375. }
  4376. else if(strcmp(status,"Downloading")==0)
  4377. {
  4378. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4379. }
  4380. else if(strcmp(status,"Idle")==0)
  4381. {
  4382. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4383. }
  4384. else if(strcmp(status,"InstallationFailed")==0)
  4385. {
  4386. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4387. }
  4388. else if(strcmp(status,"Installing")==0)
  4389. {
  4390. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4391. }
  4392. else if(strcmp(status,"Installed")==0)
  4393. {
  4394. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4395. }
  4396. return result;
  4397. }
  4398. int sendHeartbeatRequest(int gun_index)
  4399. {
  4400. mtrace();
  4401. int result = FAIL;
  4402. char message[80]={0};
  4403. char guid[37]={0};
  4404. char tempdata[65]={0};
  4405. random_uuid(guid);
  4406. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4407. , MESSAGE_TYPE_CALL
  4408. , guid );
  4409. LWS_Send(message);
  4410. sprintf(tempdata, "Heartbeat,%d", 0);
  4411. 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*/)
  4412. {
  4413. result = PASS;
  4414. }
  4415. return result;
  4416. }
  4417. int sendStartTransactionRequest(int gun_index)
  4418. {
  4419. mtrace();
  4420. int result = FAIL;
  4421. char message[250]={0};
  4422. char guid[37]={0};
  4423. struct timeval tmnow;
  4424. struct tm *tm;
  4425. char buf[28];//, usec_buf[6];
  4426. char tempdata[65]={0};
  4427. int tempIndex = 0;
  4428. DEBUG_INFO("sendStartTransactionRequest...\n");
  4429. gettimeofday(&tmnow, NULL);
  4430. time_t t;
  4431. t = time(NULL);
  4432. /*UTC time and date*/
  4433. tm = gmtime(&t);
  4434. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4435. #if 0 // remove temporally
  4436. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4437. strcat(buf,".");
  4438. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4439. strcat(buf,usec_buf);
  4440. #endif
  4441. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4442. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4443. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4444. // clear StartTransaction Response
  4445. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4446. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4447. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4448. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4449. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4450. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4452. {
  4453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4454. {
  4455. tempIndex = ((gun_index==2) ? 1: 0);
  4456. }
  4457. else
  4458. {
  4459. tempIndex = gun_index;
  4460. }
  4461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4462. {
  4463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4464. {
  4465. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4466. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4467. }
  4468. }
  4469. }
  4470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4471. {
  4472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4473. {
  4474. tempIndex = ((gun_index==2) ? 1: 0);
  4475. }
  4476. else
  4477. {
  4478. tempIndex = gun_index;
  4479. }
  4480. for (int index = 0; index < CCS_QUANTITY; index++)
  4481. {
  4482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4483. {
  4484. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4485. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4486. }
  4487. }
  4488. }
  4489. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4490. {
  4491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4492. {
  4493. tempIndex = ((gun_index==2) ? 1: 0);
  4494. }
  4495. else
  4496. {
  4497. tempIndex = gun_index;
  4498. }
  4499. for (int index = 0; index < GB_QUANTITY; index++)
  4500. {
  4501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4502. {
  4503. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4504. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4505. }
  4506. }
  4507. }
  4508. else if(gunType[gun_index] == GUN_TYPE_DO)
  4509. {
  4510. tempIndex = gun_index;
  4511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4512. {
  4513. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4514. {
  4515. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4516. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4517. }
  4518. }
  4519. }
  4520. else
  4521. {
  4522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4523. {
  4524. tempIndex = 2;
  4525. }
  4526. else
  4527. {
  4528. tempIndex = gun_index;
  4529. }
  4530. for (int index = 0; index < AC_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4533. {
  4534. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4535. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4536. }
  4537. }
  4538. }
  4539. random_uuid(guid);
  4540. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4541. {
  4542. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4543. , gun_index +1
  4544. , MESSAGE_TYPE_CALL
  4545. , guid
  4546. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4547. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4548. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4549. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4550. }
  4551. else
  4552. {
  4553. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4554. , gun_index +1
  4555. , MESSAGE_TYPE_CALL
  4556. , guid
  4557. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4558. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4559. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4560. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4561. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4562. }
  4563. #if 1
  4564. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4565. 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*/)
  4566. {
  4567. result = PASS;
  4568. }
  4569. #endif
  4570. strcpy(queuedata, message);
  4571. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4572. OCPP_insert_transaction_msg(YES, queuedata);
  4573. return result;
  4574. }
  4575. int sendStatusNotificationRequest(int gun_index)
  4576. {
  4577. mtrace();
  4578. int result = FAIL;
  4579. char message[600]={0};
  4580. char guid[37];
  4581. int currentStatus = 0;
  4582. struct timeval tmnow;
  4583. struct tm *tm;
  4584. char buf[28];//, usec_buf[6];
  4585. char tempdata[65]={0};
  4586. int tempIndex = 0;
  4587. uint8_t isStateChanged = TRUE;
  4588. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4589. gettimeofday(&tmnow, NULL);
  4590. time_t t;
  4591. t = time(NULL);
  4592. /*UTC time and date*/
  4593. tm = gmtime(&t);
  4594. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4595. #if 0 // remove temporally
  4596. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4597. strcat(buf,".");
  4598. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4599. strcat(buf,usec_buf);
  4600. #endif
  4601. //printf("%s",buf);
  4602. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4603. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4604. // it's option
  4605. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4606. /*
  4607. enum _SYSTEM_STATUS
  4608. {
  4609. S_BOOTING = 0,
  4610. S_IDLE, = 1
  4611. S_AUTHORIZING, =2
  4612. S_REASSIGN_CHECK, =3
  4613. S_REASSIGN, =4
  4614. S_PRECHARGE, =5
  4615. S_PREPARING_FOR_EV, =6
  4616. S_PREPARING_FOR_EVSE, =7
  4617. S_CHARGING, =8
  4618. S_TERMINATING, =9
  4619. S_COMPLETE, =10
  4620. S_ALARM, =11
  4621. S_FAULT =12
  4622. }
  4623. */
  4624. //check Transaction active
  4625. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4626. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4627. {
  4628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4629. {
  4630. tempIndex = ((gun_index==2) ? 1: 0);
  4631. }
  4632. else
  4633. {
  4634. tempIndex = gun_index;
  4635. }
  4636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4637. {
  4638. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4639. {
  4640. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4641. {
  4642. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4643. {
  4644. currentStatus = Preparing; //OCPP Status: Preparing
  4645. }
  4646. else
  4647. {
  4648. currentStatus = Available; //OCPP Status: Available
  4649. }
  4650. }
  4651. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4652. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4653. ) //S_PRECHARGE
  4654. {
  4655. currentStatus = Preparing; //OCPP Status: Preparing
  4656. }
  4657. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4658. {
  4659. currentStatus = Charging; //OCPP Status: Charging
  4660. }
  4661. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4662. {
  4663. currentStatus = Finishing; //OCPP Status: Finishing
  4664. }
  4665. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4666. {
  4667. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4668. }
  4669. 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
  4670. {
  4671. currentStatus = Unavailable; //OCPP Status: Unavailable
  4672. }
  4673. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4674. {
  4675. currentStatus = Faulted; //OCPP Status: Faulted
  4676. }
  4677. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4678. {
  4679. currentStatus = Reserved; //OCPP Status: Reserved
  4680. }
  4681. } //end of the same index
  4682. }//end of for CHAdeMO_QUANTITY
  4683. }
  4684. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4685. {
  4686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4687. {
  4688. tempIndex = ((gun_index==2) ? 1: 0);
  4689. }
  4690. else
  4691. {
  4692. tempIndex = gun_index;
  4693. }
  4694. for (int index = 0; index < CCS_QUANTITY; index++)
  4695. {
  4696. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4699. {
  4700. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4701. {
  4702. currentStatus = Preparing; //OCPP Status: Preparing
  4703. }
  4704. else
  4705. {
  4706. currentStatus = Available; //OCPP Status: Available
  4707. }
  4708. }
  4709. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4710. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4711. ) //S_PRECHARGE
  4712. {
  4713. currentStatus = Preparing; //OCPP Status: Preparing
  4714. }
  4715. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4716. {
  4717. currentStatus = Charging; //OCPP Status: Charging
  4718. }
  4719. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4720. {
  4721. currentStatus = Finishing; //OCPP Status: Finishing
  4722. }
  4723. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4724. {
  4725. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4726. }
  4727. 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
  4728. {
  4729. currentStatus = Unavailable; //OCPP Status : Unavailable
  4730. }
  4731. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4732. {
  4733. currentStatus = Faulted; //OCPP Status: Faulted
  4734. }
  4735. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4736. {
  4737. currentStatus = Reserved; //OCPP Status: Reserved
  4738. }
  4739. } //end of the same index
  4740. } // end of for CCS_QUANTITY
  4741. }
  4742. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4743. {
  4744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4745. {
  4746. tempIndex = ((gun_index==2) ? 1: 0);
  4747. }
  4748. else
  4749. {
  4750. tempIndex = gun_index;
  4751. }
  4752. for (int index = 0; index < GB_QUANTITY; index++)
  4753. {
  4754. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4755. {
  4756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4757. {
  4758. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4759. {
  4760. currentStatus = Preparing; //OCPP Status: Preparing
  4761. }
  4762. else
  4763. {
  4764. currentStatus = Available; //OCPP Status: Available
  4765. }
  4766. }
  4767. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4768. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4769. ) //S_PRECHARGE
  4770. {
  4771. currentStatus = Preparing; //OCPP Status: Preparing
  4772. }
  4773. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4774. {
  4775. currentStatus = Charging; //OCPP Status: Charging
  4776. }
  4777. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4778. {
  4779. currentStatus = Finishing; //OCPP Status: Finishing
  4780. }
  4781. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4782. {
  4783. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4784. }
  4785. 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
  4786. {
  4787. currentStatus = Unavailable; //OCPP Status: Unavailable
  4788. }
  4789. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4790. {
  4791. currentStatus = Faulted; //OCPP Status: Faulted
  4792. }
  4793. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4794. {
  4795. currentStatus = Reserved; //OCPP Status: Reserved
  4796. }
  4797. } //end of the same index
  4798. } // end of for GB_QUANTITY
  4799. }
  4800. else if(gunType[gun_index] == GUN_TYPE_DO)
  4801. {
  4802. tempIndex = gun_index;
  4803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4804. {
  4805. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4806. {
  4807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4808. {
  4809. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4810. {
  4811. currentStatus = Preparing; //OCPP Status: Preparing
  4812. }
  4813. else
  4814. {
  4815. currentStatus = Available; //OCPP Status: Available
  4816. }
  4817. }
  4818. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4819. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4820. ) //S_PRECHARGE
  4821. {
  4822. currentStatus = Preparing; //OCPP Status: Preparing
  4823. }
  4824. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4825. {
  4826. currentStatus = Charging; //OCPP Status: Charging
  4827. }
  4828. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4829. {
  4830. currentStatus = Finishing; //OCPP Status: Finishing
  4831. }
  4832. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4833. {
  4834. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4835. }
  4836. 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
  4837. {
  4838. currentStatus = Unavailable; //OCPP Status: Unavailable
  4839. }
  4840. 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
  4841. {
  4842. currentStatus = Faulted; //OCPP Status: Faulted
  4843. }
  4844. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4845. {
  4846. currentStatus = Reserved; //OCPP Status: Reserved
  4847. }
  4848. } //end of the same index
  4849. }
  4850. }
  4851. else
  4852. {
  4853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4854. {
  4855. tempIndex = 2;
  4856. }
  4857. else
  4858. {
  4859. tempIndex = gun_index;
  4860. }
  4861. for (int index = 0; index < AC_QUANTITY; index++)
  4862. {
  4863. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4864. {
  4865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4866. {
  4867. 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))
  4868. {
  4869. currentStatus = Preparing; //OCPP Status: Preparing
  4870. }
  4871. else
  4872. {
  4873. currentStatus = Available; //OCPP Status: Available
  4874. }
  4875. }
  4876. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4877. {
  4878. currentStatus = Preparing; //OCPP Status: Preparing
  4879. }
  4880. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4881. {
  4882. currentStatus = Charging; //OCPP Status: Charging
  4883. }
  4884. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4885. {
  4886. currentStatus = Finishing; //OCPP Status: Finishing
  4887. }
  4888. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4889. {
  4890. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4891. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4892. else
  4893. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4894. }
  4895. 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
  4896. {
  4897. currentStatus = Unavailable; //OCPP Status: Unavailable
  4898. }
  4899. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4900. {
  4901. currentStatus = Faulted; //OCPP Status: Faulted
  4902. }
  4903. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4904. {
  4905. currentStatus = Reserved; //OCPP Status: Reserved
  4906. }
  4907. }//end of the same index
  4908. }//end of for AC_QUANTITY
  4909. }
  4910. //it's option
  4911. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4912. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4913. {
  4914. isStateChanged = FALSE;
  4915. }
  4916. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4917. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4918. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4919. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4920. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4921. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4922. random_uuid(guid);
  4923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4924. , MESSAGE_TYPE_CALL
  4925. , guid
  4926. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4927. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4928. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4929. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4930. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4931. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4932. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4933. if((server_sign == TRUE) && isStateChanged)
  4934. {
  4935. LWS_Send(message);
  4936. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4937. 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*/)
  4938. {
  4939. //DEBUG_ERROR("statusNotification mapitem pass");
  4940. result = PASS;
  4941. }
  4942. }
  4943. else
  4944. {
  4945. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4946. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4947. result = PASS;
  4948. }
  4949. return result;
  4950. }
  4951. int sendStopTransactionRequest(int gun_index)
  4952. {
  4953. mtrace();
  4954. int result = FAIL;
  4955. //char message[1500]={0};
  4956. char guid[37]={0};
  4957. char tempdata[65]={0};
  4958. int tempIndex = 0;
  4959. char TempStopTransaction[256];
  4960. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4961. //int idx_sample=0;
  4962. DEBUG_INFO("sendStopTransactionRequest \n");
  4963. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4964. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4965. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4966. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4968. {
  4969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4970. {
  4971. tempIndex = ((gun_index==2) ? 1: 0);
  4972. }
  4973. else
  4974. {
  4975. tempIndex = gun_index;
  4976. }
  4977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4978. {
  4979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4980. {
  4981. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4982. }
  4983. }// END OF CHAdeMO_QUANTITY
  4984. }
  4985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4986. {
  4987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4988. {
  4989. tempIndex = ((gun_index==2) ? 1: 0);
  4990. }
  4991. else
  4992. {
  4993. tempIndex = gun_index;
  4994. }
  4995. for (int index = 0; index < CCS_QUANTITY; index++)
  4996. {
  4997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4998. {
  4999. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5000. }
  5001. }// END OF CCS_QUANTITY
  5002. }
  5003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5004. {
  5005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5006. {
  5007. tempIndex = ((gun_index==2) ? 1: 0);
  5008. }
  5009. else
  5010. {
  5011. tempIndex = gun_index;
  5012. }
  5013. for (int index = 0; index < GB_QUANTITY; index++)
  5014. {
  5015. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5016. {
  5017. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5018. }
  5019. }// END OF GB_QUANTITY
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_DO)
  5022. {
  5023. tempIndex = gun_index;
  5024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5027. {
  5028. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5029. }
  5030. }// END OF GB_QUANTITY
  5031. }
  5032. else
  5033. {
  5034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5035. {
  5036. tempIndex = 2;
  5037. }
  5038. else
  5039. {
  5040. tempIndex = gun_index;
  5041. }
  5042. for (int index = 0; index < AC_QUANTITY; index++)
  5043. {
  5044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5045. {
  5046. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5047. }
  5048. }// END OF AC_QUANTITY
  5049. }
  5050. //====================================== Stop Transaction Time =====================================================
  5051. struct timeval tmnow;
  5052. struct tm *tm;
  5053. char buf[28];//, usec_buf[6];
  5054. gettimeofday(&tmnow, NULL);
  5055. time_t t;
  5056. t = time(NULL);
  5057. /*UTC time and date*/
  5058. tm = gmtime(&t);
  5059. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5061. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5062. random_uuid(guid);
  5063. /***********************************transactionData******************************************************/
  5064. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5066. //=================================
  5067. // Transaction_Begin
  5068. //=================================
  5069. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5070. {
  5071. //============================================ Energy.Active.Import.Interval ================================
  5072. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5075. 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*/]);
  5076. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5077. 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))
  5078. {
  5079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5080. }
  5081. else
  5082. {
  5083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5084. }
  5085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5087. }
  5088. //=================================
  5089. // Transaction_End
  5090. //=================================
  5091. // ================================= Current.Import L1 ===============================================
  5092. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5093. {
  5094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5096. {
  5097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5098. {
  5099. tempIndex = ((gun_index==2) ? 1: 0);
  5100. }
  5101. else
  5102. {
  5103. tempIndex = gun_index;
  5104. }
  5105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5108. {
  5109. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5110. }
  5111. }// End of for CHAdeMO_QUANTITY
  5112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5113. }
  5114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5115. {
  5116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5117. {
  5118. tempIndex = ((gun_index==2) ? 1: 0);
  5119. }
  5120. else
  5121. {
  5122. tempIndex = gun_index;
  5123. }
  5124. for (int index = 0; index < CCS_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5127. {
  5128. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5129. }
  5130. }// End of for CCS_QUANTITY
  5131. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5132. }
  5133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5134. {
  5135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5136. {
  5137. tempIndex = ((gun_index==2) ? 1: 0);
  5138. }
  5139. else
  5140. {
  5141. tempIndex = gun_index;
  5142. }
  5143. for (int index = 0; index < GB_QUANTITY; index++)
  5144. {
  5145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5146. {
  5147. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5148. }
  5149. }// End of for GB_QUANTITY
  5150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5151. }
  5152. else if(gunType[gun_index] == GUN_TYPE_DO)
  5153. {
  5154. tempIndex = gun_index;
  5155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5156. {
  5157. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5158. {
  5159. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5160. }
  5161. }
  5162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5163. }
  5164. else
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5167. {
  5168. tempIndex = 2;
  5169. }
  5170. else
  5171. {
  5172. tempIndex = gun_index;
  5173. }
  5174. for (int index = 0; index < AC_QUANTITY; index++)
  5175. {
  5176. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5177. {
  5178. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5179. }
  5180. }// End of for AC_QUANTITY
  5181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5182. }
  5183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5187. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5188. }
  5189. // ================================= Energy.Active.Import.Interval ==============================================
  5190. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5191. {
  5192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5193. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5194. {
  5195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5196. {
  5197. tempIndex = ((gun_index==2) ? 1: 0);
  5198. }
  5199. else
  5200. {
  5201. tempIndex = gun_index;
  5202. }
  5203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5204. {
  5205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5206. {
  5207. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5208. }
  5209. }// END OF CHAdeMO_QUANTITY
  5210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5211. }
  5212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5213. {
  5214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5215. {
  5216. tempIndex = ((gun_index==2) ? 1: 0);
  5217. }
  5218. else
  5219. {
  5220. tempIndex = gun_index;
  5221. }
  5222. for (int index = 0; index < CCS_QUANTITY; index++)
  5223. {
  5224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5225. {
  5226. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5227. }
  5228. }// END OF CCS_QUANTITY
  5229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5230. }
  5231. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5232. {
  5233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5234. {
  5235. tempIndex = ((gun_index==2) ? 1: 0);
  5236. }
  5237. else
  5238. {
  5239. tempIndex = gun_index;
  5240. }
  5241. for (int index = 0; index < GB_QUANTITY; index++)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5244. {
  5245. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5246. }
  5247. }// END OF GB_QUANTITY
  5248. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5249. }
  5250. else if(gunType[gun_index] == GUN_TYPE_DO)
  5251. {
  5252. tempIndex = gun_index;
  5253. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5254. {
  5255. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5256. {
  5257. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5258. }
  5259. }
  5260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5261. }
  5262. else
  5263. {
  5264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5265. {
  5266. tempIndex = 2;
  5267. }
  5268. else
  5269. {
  5270. tempIndex = gun_index;
  5271. }
  5272. for (int index = 0; index < AC_QUANTITY; index++)
  5273. {
  5274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5275. {
  5276. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5277. }
  5278. }// END OF AC_QUANTITY
  5279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5280. }
  5281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5284. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5286. }
  5287. //=================================== Power.Active.Import ==================================================
  5288. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5289. {
  5290. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5292. {
  5293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5294. {
  5295. tempIndex = ((gun_index==2) ? 1: 0);
  5296. }
  5297. else
  5298. {
  5299. tempIndex = gun_index;
  5300. }
  5301. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5304. {
  5305. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5306. }
  5307. } // End for CHAdeMO_QUANTITY
  5308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5309. }
  5310. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5311. {
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5313. {
  5314. tempIndex = ((gun_index==2) ? 1: 0);
  5315. }
  5316. else
  5317. {
  5318. tempIndex = gun_index;
  5319. }
  5320. for (int index = 0; index < CCS_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5325. }
  5326. } // END for CCS_QUANTITY
  5327. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5328. }
  5329. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5330. {
  5331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5332. {
  5333. tempIndex = ((gun_index==2) ? 1: 0);
  5334. }
  5335. else
  5336. {
  5337. tempIndex = gun_index;
  5338. }
  5339. for (int index = 0; index < GB_QUANTITY; index++)
  5340. {
  5341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5342. {
  5343. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5344. }
  5345. }// END for GB_QUANTITY
  5346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5347. }
  5348. else if(gunType[gun_index] == GUN_TYPE_DO)
  5349. {
  5350. tempIndex = gun_index;
  5351. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5352. {
  5353. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5354. {
  5355. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5356. }
  5357. }
  5358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5359. }
  5360. else
  5361. {
  5362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5363. {
  5364. tempIndex = 2;
  5365. }
  5366. else
  5367. {
  5368. tempIndex = gun_index;
  5369. }
  5370. for (int index = 0; index < AC_QUANTITY; index++)
  5371. {
  5372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5373. {
  5374. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5375. }
  5376. } // END for AC_QUANTITY
  5377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5378. }
  5379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5382. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5383. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5384. }
  5385. //============================ Voltage L1 ====================================
  5386. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5387. {
  5388. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5390. {
  5391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5392. {
  5393. tempIndex = ((gun_index==2) ? 1: 0);
  5394. }
  5395. else
  5396. {
  5397. tempIndex = gun_index;
  5398. }
  5399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5400. {
  5401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5402. {
  5403. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5404. }
  5405. } // END OF FOR CHAdeMO_QUANTITY
  5406. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5407. }
  5408. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5409. {
  5410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5411. {
  5412. tempIndex = ((gun_index==2) ? 1: 0);
  5413. }
  5414. else
  5415. {
  5416. tempIndex = gun_index;
  5417. }
  5418. for (int index = 0; index < CCS_QUANTITY; index++)
  5419. {
  5420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5421. {
  5422. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5423. }
  5424. } // END OF FOR CCS_QUANTITY
  5425. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5426. }
  5427. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5428. {
  5429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5430. {
  5431. tempIndex = ((gun_index==2) ? 1: 0);
  5432. }
  5433. else
  5434. {
  5435. tempIndex = gun_index;
  5436. }
  5437. for (int index = 0; index < GB_QUANTITY; index++)
  5438. {
  5439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5440. {
  5441. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5442. }
  5443. } // END OF FOR GB_QUANTITY
  5444. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5445. }
  5446. else if(gunType[gun_index] == GUN_TYPE_DO)
  5447. {
  5448. tempIndex = gun_index;
  5449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5450. {
  5451. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5452. {
  5453. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5454. }
  5455. }
  5456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5457. }
  5458. else
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5461. {
  5462. tempIndex = 2;
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < AC_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5471. {
  5472. 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
  5473. }
  5474. } // END OF FOR AC_QUANTITY
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5476. }
  5477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5482. }
  5483. //====================== End SoC ================================
  5484. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5485. {
  5486. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5487. 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))
  5488. {
  5489. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5490. {
  5491. tempIndex = ((gun_index==2) ? 1: 0);
  5492. }
  5493. else
  5494. {
  5495. tempIndex = gun_index;
  5496. }
  5497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5498. {
  5499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5502. {
  5503. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5504. }
  5505. }
  5506. }
  5507. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5508. {
  5509. for (int index = 0; index < CCS_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5512. {
  5513. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5514. }
  5515. }
  5516. }
  5517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5518. {
  5519. for (int index = 0; index < GB_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5522. {
  5523. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5524. }
  5525. }
  5526. }
  5527. else if(gunType[gun_index] == GUN_TYPE_DO)
  5528. {
  5529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5532. {
  5533. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5534. }
  5535. }
  5536. }
  5537. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5539. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5540. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5541. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5542. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5543. } // END FOR DC CASE
  5544. }
  5545. // ================================= Current.Import L2 ===============================================
  5546. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5547. {
  5548. // AC 3 phse L2 current
  5549. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5550. {
  5551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5552. {
  5553. tempIndex = 2;
  5554. }
  5555. else
  5556. {
  5557. tempIndex = gun_index;
  5558. }
  5559. for (int index = 0; index < AC_QUANTITY; index++)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5562. {
  5563. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5564. }
  5565. }// End of for AC_QUANTITY
  5566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5567. }
  5568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5573. }
  5574. // ================================= Current.Import L3 ===============================================
  5575. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5576. {
  5577. // AC 3 phse L3 current
  5578. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5579. {
  5580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5581. {
  5582. tempIndex = 2;
  5583. }
  5584. else
  5585. {
  5586. tempIndex = gun_index;
  5587. }
  5588. for (int index = 0; index < AC_QUANTITY; index++)
  5589. {
  5590. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5591. {
  5592. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5593. }
  5594. }// End of for AC_QUANTITY
  5595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5596. }
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5602. }
  5603. //============================ Voltage L2 ====================================
  5604. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5605. {
  5606. // AC 3 phse L2 voltage
  5607. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5608. {
  5609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5610. {
  5611. tempIndex = 2;
  5612. }
  5613. else
  5614. {
  5615. tempIndex = gun_index;
  5616. }
  5617. for (int index = 0; index < AC_QUANTITY; index++)
  5618. {
  5619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5620. {
  5621. 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
  5622. }
  5623. } // END OF FOR AC_QUANTITY
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5625. }
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5631. }
  5632. //============================ Voltage L3 ====================================
  5633. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5634. {
  5635. // AC 3 phse L3 voltage
  5636. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5637. {
  5638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5639. {
  5640. tempIndex = 2;
  5641. }
  5642. else
  5643. {
  5644. tempIndex = gun_index;
  5645. }
  5646. for (int index = 0; index < AC_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5649. {
  5650. 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
  5651. }
  5652. } // END OF FOR AC_QUANTITY
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5654. }
  5655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5660. }
  5661. //====================== Start SoC ================================
  5662. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5663. {
  5664. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5665. 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))
  5666. {
  5667. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5668. {
  5669. tempIndex = ((gun_index==2) ? 1: 0);
  5670. }
  5671. else
  5672. {
  5673. tempIndex = gun_index;
  5674. }
  5675. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5676. {
  5677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5678. {
  5679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5680. {
  5681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5682. }
  5683. }
  5684. }
  5685. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5686. {
  5687. for (int index = 0; index < CCS_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5692. }
  5693. }
  5694. }
  5695. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5696. {
  5697. for (int index = 0; index < GB_QUANTITY; index++)
  5698. {
  5699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5700. {
  5701. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5702. }
  5703. }
  5704. }
  5705. else if(gunType[gun_index] == GUN_TYPE_DO)
  5706. {
  5707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5712. }
  5713. }
  5714. }
  5715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5719. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5721. } // END FOR DC CASE
  5722. }
  5723. //================================================ Message create ====================================================
  5724. json_object *StopTransaction = json_object_new_object();
  5725. json_object *transactionDatas = json_object_new_array();
  5726. json_object *sampledValues = json_object_new_array();
  5727. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5728. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5729. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5730. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5731. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5732. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5733. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5734. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5735. {
  5736. json_object *transactionData = json_object_new_object();
  5737. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5738. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5739. {
  5740. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5741. {
  5742. json_object *sampledValue = json_object_new_object();
  5743. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5744. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5745. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5746. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5747. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5748. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5749. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5750. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5751. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5752. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5753. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5754. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5755. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5756. json_object_array_add(sampledValues, sampledValue);
  5757. }
  5758. }
  5759. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5760. json_object_array_add(transactionDatas, transactionData);
  5761. }
  5762. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5763. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5764. ,MESSAGE_TYPE_CALL
  5765. ,guid
  5766. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5767. json_object_put(StopTransaction);
  5768. #if 1 // for TempStopTransaction
  5769. //Delete TempStopTransaction
  5770. if((access(TempStopTransaction,F_OK))!=-1)
  5771. {
  5772. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5773. }
  5774. #endif
  5775. #if 1
  5776. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5778. {
  5779. result = PASS;
  5780. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5781. }
  5782. #endif
  5783. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5784. OCPP_insert_transaction_msg(NO, queuedata);
  5785. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5786. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5787. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5788. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5789. {
  5790. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5791. }
  5792. //for test
  5793. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5794. return result;
  5795. }
  5796. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5797. {
  5798. mtrace();
  5799. int result = FAIL;
  5800. char guid[37]={0};
  5801. char tempdata[65]={0};
  5802. int tempIndex = 0;
  5803. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5804. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5805. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5806. //set value
  5807. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5808. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5809. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5810. -1);
  5811. random_uuid(guid);
  5812. //UTC Date time
  5813. struct timeval tmnow;
  5814. struct tm *tm;
  5815. char buf[28];//, usec_buf[6];
  5816. gettimeofday(&tmnow, NULL);
  5817. time_t t;
  5818. t = time(NULL);
  5819. /*UTC time and date*/
  5820. tm = gmtime(&t);
  5821. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5823. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5824. //********************************(1)Current.Import L1************************************************/
  5825. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5826. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5827. (dataType == ReadingContext_Trigger))
  5828. {
  5829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5830. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5833. {
  5834. tempIndex = ((gun_index==2) ? 1: 0);
  5835. }
  5836. else
  5837. {
  5838. tempIndex = gun_index;
  5839. }
  5840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5843. {
  5844. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5845. }
  5846. }
  5847. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5848. }
  5849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5850. {
  5851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5852. {
  5853. tempIndex = ((gun_index==2) ? 1: 0);
  5854. }
  5855. else
  5856. {
  5857. tempIndex = gun_index;
  5858. }
  5859. for (int index = 0; index < CCS_QUANTITY; index++)
  5860. {
  5861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5862. {
  5863. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5864. }
  5865. }
  5866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5867. }
  5868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5869. {
  5870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5871. {
  5872. tempIndex = ((gun_index==2) ? 1: 0);
  5873. }
  5874. else
  5875. {
  5876. tempIndex = gun_index;
  5877. }
  5878. for (int index = 0; index < GB_QUANTITY; index++)
  5879. {
  5880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5881. {
  5882. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5883. }
  5884. }
  5885. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5886. }
  5887. else if(gunType[gun_index] == GUN_TYPE_DO)
  5888. {
  5889. tempIndex = gun_index;
  5890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5891. {
  5892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5893. {
  5894. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5895. }
  5896. }
  5897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5898. }
  5899. else
  5900. {
  5901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5902. {
  5903. tempIndex = 2;
  5904. }
  5905. else
  5906. {
  5907. tempIndex = gun_index;
  5908. }
  5909. for (int index = 0; index < AC_QUANTITY; index++)
  5910. {
  5911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5912. {
  5913. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5914. }
  5915. }
  5916. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5917. }
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5923. }
  5924. //********************************(2)Energy.Active.Import.Register ************************************************/
  5925. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5926. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5927. (dataType == ReadingContext_Trigger))
  5928. {
  5929. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5930. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5931. {
  5932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5933. {
  5934. tempIndex = ((gun_index==2) ? 1: 0);
  5935. }
  5936. else
  5937. {
  5938. tempIndex = gun_index;
  5939. }
  5940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5943. {
  5944. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5945. }
  5946. }
  5947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5948. }
  5949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5952. {
  5953. tempIndex = ((gun_index==2) ? 1: 0);
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < CCS_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5962. {
  5963. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5964. }
  5965. }
  5966. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5967. }
  5968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5969. {
  5970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5971. {
  5972. tempIndex = ((gun_index==2) ? 1: 0);
  5973. }
  5974. else
  5975. {
  5976. tempIndex = gun_index;
  5977. }
  5978. for (int index = 0; index < GB_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5983. }
  5984. }
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5986. }
  5987. else if(gunType[gun_index] == GUN_TYPE_DO)
  5988. {
  5989. tempIndex = gun_index;
  5990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5995. }
  5996. }
  5997. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5998. }
  5999. else
  6000. {
  6001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6002. {
  6003. tempIndex = 2;
  6004. }
  6005. else
  6006. {
  6007. tempIndex = gun_index;
  6008. }
  6009. for (int index = 0; index < AC_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6017. }
  6018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6023. }
  6024. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6027. (dataType == ReadingContext_Trigger))
  6028. {
  6029. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6031. {
  6032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6033. {
  6034. tempIndex = ((gun_index==2) ? 1: 0);
  6035. }
  6036. else
  6037. {
  6038. tempIndex = gun_index;
  6039. }
  6040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6045. }
  6046. } // END OF FOR CHAdeMO_QUANTITY
  6047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6048. }
  6049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6050. {
  6051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6052. {
  6053. tempIndex = ((gun_index==2) ? 1: 0);
  6054. }
  6055. else
  6056. {
  6057. tempIndex = gun_index;
  6058. }
  6059. for (int index = 0; index < CCS_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6064. }
  6065. } // END OF CCS_QUANTITY
  6066. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6067. }
  6068. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6069. {
  6070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6071. {
  6072. tempIndex = ((gun_index==2) ? 1: 0);
  6073. }
  6074. else
  6075. {
  6076. tempIndex = gun_index;
  6077. }
  6078. for (int index = 0; index < GB_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6083. }
  6084. } // END OF GB_QUANTITY
  6085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_DO)
  6088. {
  6089. tempIndex = gun_index;
  6090. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6095. }
  6096. }
  6097. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6098. }
  6099. else
  6100. {
  6101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6102. {
  6103. tempIndex = 2;
  6104. }
  6105. else
  6106. {
  6107. tempIndex = gun_index;
  6108. }
  6109. for (int index = 0; index < AC_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6114. }
  6115. }
  6116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6117. }
  6118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6120. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6121. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6122. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6123. }
  6124. //********************************(4)Power.Active.Import************************************************/
  6125. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6126. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6127. (dataType == ReadingContext_Trigger))
  6128. {
  6129. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6130. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6131. {
  6132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6133. {
  6134. tempIndex = ((gun_index==2) ? 1: 0);
  6135. }
  6136. else
  6137. {
  6138. tempIndex = gun_index;
  6139. }
  6140. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6141. {
  6142. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6143. {
  6144. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6145. }
  6146. } // END OF FOR
  6147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6148. }
  6149. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < CCS_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6162. {
  6163. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6164. }
  6165. }
  6166. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6167. }
  6168. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6169. {
  6170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6171. {
  6172. tempIndex = ((gun_index==2) ? 1: 0);
  6173. }
  6174. else
  6175. {
  6176. tempIndex = gun_index;
  6177. }
  6178. for (int index = 0; index < GB_QUANTITY; index++)
  6179. {
  6180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6181. {
  6182. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6183. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6184. }
  6185. }
  6186. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6187. }
  6188. else if(gunType[gun_index] == GUN_TYPE_DO)
  6189. {
  6190. tempIndex = gun_index;
  6191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6192. {
  6193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6194. {
  6195. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6196. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6197. }
  6198. }
  6199. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6200. }
  6201. else
  6202. {
  6203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6204. {
  6205. tempIndex = 2;
  6206. }
  6207. else
  6208. {
  6209. tempIndex = gun_index;
  6210. }
  6211. for (int index = 0; index < AC_QUANTITY; index++)
  6212. {
  6213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6214. {
  6215. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6216. }
  6217. }
  6218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6219. }
  6220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6223. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6224. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6225. }
  6226. //***********************************************(5)VOLTAGE L1******************************************************/
  6227. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6228. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6229. (dataType == ReadingContext_Trigger))
  6230. {
  6231. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6232. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6233. {
  6234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6235. {
  6236. tempIndex = ((gun_index==2) ? 1: 0);
  6237. }
  6238. else
  6239. {
  6240. tempIndex = gun_index;
  6241. }
  6242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6245. {
  6246. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6247. }
  6248. }
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6250. }
  6251. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6252. {
  6253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6254. {
  6255. tempIndex = ((gun_index==2) ? 1: 0);
  6256. }
  6257. else
  6258. {
  6259. tempIndex = gun_index;
  6260. }
  6261. for (int index = 0; index < CCS_QUANTITY; index++)
  6262. {
  6263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6264. {
  6265. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6266. }
  6267. }
  6268. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6269. }
  6270. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6271. {
  6272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6273. {
  6274. tempIndex = ((gun_index==2) ? 1: 0);
  6275. }
  6276. else
  6277. {
  6278. tempIndex = gun_index;
  6279. }
  6280. for (int index = 0; index < GB_QUANTITY; index++)
  6281. {
  6282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6283. {
  6284. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6285. }
  6286. }
  6287. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6288. }
  6289. else if(gunType[gun_index] == GUN_TYPE_DO)
  6290. {
  6291. tempIndex = gun_index;
  6292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6295. {
  6296. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6300. }
  6301. else
  6302. {
  6303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6304. {
  6305. tempIndex = 2;
  6306. }
  6307. else
  6308. {
  6309. tempIndex = gun_index;
  6310. }
  6311. for (int index = 0; index < AC_QUANTITY; index++)
  6312. {
  6313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6314. {
  6315. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6316. }
  6317. }
  6318. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6319. }
  6320. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6321. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6323. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6324. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6325. }
  6326. //***********************************************(6)SOC******************************************************/
  6327. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6328. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6329. (dataType == ReadingContext_Trigger))
  6330. {
  6331. 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))
  6332. {
  6333. //idx_sample=5;
  6334. //sampledValue = NULL;
  6335. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6336. {
  6337. tempIndex = ((gun_index==2) ? 1: 0);
  6338. }
  6339. else
  6340. {
  6341. tempIndex = gun_index;
  6342. }
  6343. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6344. {
  6345. //tempIndex = ((gun_index==2) ? 1: 0);
  6346. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6347. {
  6348. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6349. {
  6350. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6351. }
  6352. }
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6355. {
  6356. //tempIndex = ((gun_index==2) ? 1: 0);
  6357. for (int index = 0; index < CCS_QUANTITY; index++)
  6358. {
  6359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6360. {
  6361. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6362. }
  6363. }
  6364. }
  6365. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6366. {
  6367. //tempIndex = ((gun_index==2) ? 1: 0);
  6368. for (int index = 0; index < GB_QUANTITY; index++)
  6369. {
  6370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6371. {
  6372. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6373. }
  6374. }
  6375. }
  6376. else if(gunType[gun_index] == GUN_TYPE_DO)
  6377. {
  6378. //tempIndex = ((gun_index==2) ? 1: 0);
  6379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6384. }
  6385. }
  6386. }
  6387. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6388. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6389. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6390. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6391. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6392. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6393. }
  6394. }
  6395. //********************************(7)Current.Import L2************************************************/
  6396. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6397. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6398. (dataType == ReadingContext_Trigger))
  6399. {
  6400. // Only for AC 3 phase
  6401. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6402. {
  6403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6404. {
  6405. tempIndex = 2;
  6406. }
  6407. else
  6408. {
  6409. tempIndex = gun_index;
  6410. }
  6411. for (int index = 0; index < AC_QUANTITY; index++)
  6412. {
  6413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6414. {
  6415. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6416. }
  6417. }
  6418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6419. }
  6420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6425. }
  6426. //********************************(8)Current.Import L3************************************************/
  6427. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6428. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6429. (dataType == ReadingContext_Trigger))
  6430. {
  6431. // Only for AC 3 phase
  6432. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6433. {
  6434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6435. {
  6436. tempIndex = 2;
  6437. }
  6438. else
  6439. {
  6440. tempIndex = gun_index;
  6441. }
  6442. for (int index = 0; index < AC_QUANTITY; index++)
  6443. {
  6444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6445. {
  6446. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6447. }
  6448. }
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6450. }
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6456. }
  6457. //***********************************************(9)VOLTAGE L2******************************************************/
  6458. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6459. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6460. (dataType == ReadingContext_Trigger))
  6461. {
  6462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6463. {
  6464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6465. {
  6466. tempIndex = 2;
  6467. }
  6468. else
  6469. {
  6470. tempIndex = gun_index;
  6471. }
  6472. for (int index = 0; index < AC_QUANTITY; index++)
  6473. {
  6474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6475. {
  6476. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6477. }
  6478. }
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6480. }
  6481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6484. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6486. }
  6487. //***********************************************(10)VOLTAGE L3******************************************************/
  6488. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6489. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6490. (dataType == ReadingContext_Trigger))
  6491. {
  6492. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6493. {
  6494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6495. {
  6496. tempIndex = 2;
  6497. }
  6498. else
  6499. {
  6500. tempIndex = gun_index;
  6501. }
  6502. for (int index = 0; index < AC_QUANTITY; index++)
  6503. {
  6504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6505. {
  6506. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6507. }
  6508. }
  6509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6510. }
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6516. }
  6517. //***********************************************(11)Current.Offered******************************************************/
  6518. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6519. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6520. (dataType == ReadingContext_Trigger))
  6521. {
  6522. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6523. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6524. {
  6525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6526. {
  6527. tempIndex = ((gun_index==2) ? 1: 0);
  6528. }
  6529. else
  6530. {
  6531. tempIndex = gun_index;
  6532. }
  6533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6536. {
  6537. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6538. }
  6539. } // END OF FOR CHAdeMO_QUANTITY
  6540. }
  6541. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6542. {
  6543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6544. {
  6545. tempIndex = ((gun_index==2) ? 1: 0);
  6546. }
  6547. else
  6548. {
  6549. tempIndex = gun_index;
  6550. }
  6551. for (int index = 0; index < CCS_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6554. {
  6555. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6556. }
  6557. } // END OF CCS_QUANTITY
  6558. }
  6559. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6560. {
  6561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6562. {
  6563. tempIndex = ((gun_index==2) ? 1: 0);
  6564. }
  6565. else
  6566. {
  6567. tempIndex = gun_index;
  6568. }
  6569. for (int index = 0; index < GB_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6572. {
  6573. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6574. }
  6575. } // END OF GB_QUANTITY
  6576. }
  6577. else if(gunType[gun_index] == GUN_TYPE_DO)
  6578. {
  6579. tempIndex = gun_index;
  6580. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6581. {
  6582. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6583. {
  6584. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6585. }
  6586. }
  6587. }
  6588. else
  6589. {
  6590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6591. {
  6592. tempIndex = 2;
  6593. }
  6594. else
  6595. {
  6596. tempIndex = gun_index;
  6597. }
  6598. for (int index = 0; index < AC_QUANTITY; index++)
  6599. {
  6600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6601. {
  6602. uint16_t currentOffer;
  6603. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6604. {
  6605. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6606. }
  6607. else
  6608. {
  6609. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6610. }
  6611. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6612. }
  6613. }
  6614. }
  6615. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6617. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6618. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6620. }
  6621. //***********************************************(12)Power.Offered******************************************************/
  6622. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6623. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6624. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6625. {
  6626. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6627. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6628. {
  6629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6630. {
  6631. tempIndex = ((gun_index==2) ? 1: 0);
  6632. }
  6633. else
  6634. {
  6635. tempIndex = gun_index;
  6636. }
  6637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6638. {
  6639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6640. {
  6641. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6642. }
  6643. } // END OF FOR CHAdeMO_QUANTITY
  6644. }
  6645. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6648. {
  6649. tempIndex = ((gun_index==2) ? 1: 0);
  6650. }
  6651. else
  6652. {
  6653. tempIndex = gun_index;
  6654. }
  6655. for (int index = 0; index < CCS_QUANTITY; index++)
  6656. {
  6657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6658. {
  6659. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6660. }
  6661. } // END OF CCS_QUANTITY
  6662. }
  6663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6664. {
  6665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6666. {
  6667. tempIndex = ((gun_index==2) ? 1: 0);
  6668. }
  6669. else
  6670. {
  6671. tempIndex = gun_index;
  6672. }
  6673. for (int index = 0; index < GB_QUANTITY; index++)
  6674. {
  6675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6676. {
  6677. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6678. }
  6679. } // END OF GB_QUANTITY
  6680. }
  6681. else if(gunType[gun_index] == GUN_TYPE_DO)
  6682. {
  6683. tempIndex = gun_index;
  6684. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6685. {
  6686. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6687. {
  6688. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6689. }
  6690. }
  6691. }
  6692. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6693. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6694. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6695. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6696. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6697. }
  6698. // Message create ====================================================================================================
  6699. if(TRUE)
  6700. {
  6701. json_object *MeterValueReq = json_object_new_object();
  6702. json_object *MeterValues = json_object_new_array();
  6703. json_object *sampledValues = json_object_new_array();
  6704. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6705. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6706. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6707. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6708. {
  6709. json_object *MeterValue = json_object_new_object();
  6710. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6711. {
  6712. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6713. {
  6714. json_object *sampledValue = json_object_new_object();
  6715. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6716. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6717. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6718. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6719. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6720. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6721. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6722. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6723. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6724. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6725. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6726. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6727. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6728. json_object_array_add(sampledValues, sampledValue);
  6729. }
  6730. }
  6731. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6732. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6733. json_object_array_add(MeterValues, MeterValue);
  6734. }
  6735. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6736. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6737. ,gun_index + 1
  6738. ,MESSAGE_TYPE_CALL
  6739. ,guid
  6740. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6741. json_object_put(MeterValueReq);
  6742. }
  6743. // Put request guid to hash map
  6744. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6745. 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*/)
  6746. {
  6747. result = PASS;
  6748. //DEBUG_INFO("MeterValues mapitem pass\n");
  6749. }
  6750. if((dataType != ReadingContext_Trigger) &&
  6751. (dataType != ReadingContext_Sample_Clock) &&
  6752. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6753. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6754. else
  6755. {
  6756. if(FirstHeartBeat)
  6757. LWS_Send(queuedata +2);
  6758. }
  6759. return result;
  6760. }
  6761. int sendLogStatusNotificationRequest(char *status)
  6762. {
  6763. mtrace();
  6764. int result = PASS;
  6765. char message[4096]={0};
  6766. char guid[37]={0};
  6767. char tempdata[128]={0};
  6768. json_object *LogStatusNotification = json_object_new_object();
  6769. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6770. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6771. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6772. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6773. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6774. random_uuid(guid);
  6775. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6776. json_object_put(LogStatusNotification);
  6777. LWS_Send(message);
  6778. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6779. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6780. {
  6781. result = PASS;
  6782. }
  6783. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6784. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6785. return result;
  6786. }
  6787. int sendSecurityEventNotificationRequest()
  6788. {
  6789. mtrace();
  6790. int result = PASS;
  6791. char message[4096]={0};
  6792. char guid[37]={0};
  6793. char tempdata[128]={0};
  6794. json_object *SecurityEventNotification = json_object_new_object();
  6795. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6796. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6797. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6798. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6799. random_uuid(guid);
  6800. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6801. json_object_put(SecurityEventNotification);
  6802. LWS_Send(message);
  6803. sprintf(tempdata, "SecurityEventNotification,0");
  6804. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6805. {
  6806. result = PASS;
  6807. }
  6808. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6809. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6810. return result;
  6811. }
  6812. int sendSignCertificateRequest()
  6813. {
  6814. mtrace();
  6815. int result = PASS;
  6816. char message[4096]={0};
  6817. char guid[37]={0};
  6818. char tempdata[128]={0};
  6819. json_object *SignCertificate = json_object_new_object();
  6820. DEBUG_INFO("sendSignCertificateRequest...\n");
  6821. // Read csr file content
  6822. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6823. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6824. char *line = NULL;
  6825. size_t len = 0;
  6826. while(getline(&line, &len, fp) != -1)
  6827. {
  6828. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6829. {
  6830. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6831. }
  6832. }
  6833. fclose(fp);
  6834. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6835. random_uuid(guid);
  6836. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6837. json_object_put(SignCertificate);
  6838. LWS_Send(message);
  6839. sprintf(tempdata, "SignCertificate,0");
  6840. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6841. {
  6842. result = PASS;
  6843. }
  6844. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6845. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6846. return result;
  6847. }
  6848. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6849. {
  6850. mtrace();
  6851. int result = PASS;
  6852. char message[110]={0};
  6853. char guid[37]={0};
  6854. char tempdata[65]={0};
  6855. json_object *FirmwareStatusNotification = json_object_new_object();
  6856. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6857. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6858. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6859. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6860. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6861. random_uuid(guid);
  6862. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6863. json_object_put(FirmwareStatusNotification);
  6864. LWS_Send(message);
  6865. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6866. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6867. {
  6868. result = PASS;
  6869. }
  6870. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6871. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6872. return result;
  6873. }
  6874. //==========================================
  6875. // send confirm routine
  6876. //==========================================
  6877. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6878. {
  6879. mtrace();
  6880. int result = FAIL;
  6881. char message[100]={0};
  6882. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6883. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6884. LWS_Send(message);
  6885. result = TRUE;
  6886. return result;
  6887. }
  6888. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6889. {
  6890. mtrace();
  6891. int result = FAIL;
  6892. char message[100]={0};
  6893. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6895. LWS_Send(message);
  6896. result = TRUE;
  6897. return result;
  6898. }
  6899. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6900. {
  6901. mtrace();
  6902. int result = FAIL;
  6903. char message[100]={0};
  6904. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6905. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6906. LWS_Send(message);
  6907. result = TRUE;
  6908. return result;
  6909. }
  6910. int sendClearCacheConfirmation(char *uuid,char *payload)
  6911. {
  6912. mtrace();
  6913. int result = FAIL;
  6914. char message[500]={0};
  6915. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6916. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6917. LWS_Send(message);
  6918. return result;
  6919. }
  6920. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6921. {
  6922. mtrace();
  6923. int result = FAIL;
  6924. char message[500]={0};
  6925. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6926. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6927. LWS_Send(message);
  6928. return result;
  6929. }
  6930. int sendDataTransferConfirmation(char *uuid,char *payload)
  6931. {
  6932. mtrace();
  6933. char statusStr[20]={0};
  6934. char dataStr[10]={0};
  6935. char sstr[20]={0};
  6936. int c = 0;
  6937. char *loc;
  6938. int result = FAIL;
  6939. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6940. /**********************status**************************/
  6941. loc = strstr(payload, "status");
  6942. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6943. c = 0;
  6944. while (loc[3+strlen("status")+c] != '\"')
  6945. {
  6946. sstr[c] = loc[3+strlen("status")+c];
  6947. c++;
  6948. }
  6949. sstr[c] = '\0';
  6950. strcpy(statusStr, sstr);
  6951. /**********************data**************************/
  6952. loc = strstr(payload, "data");
  6953. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6954. c = 0;
  6955. while (loc[3+strlen("data")+c] != '\"')
  6956. {
  6957. sstr[c] = loc[3+strlen("data")+c];
  6958. c++;
  6959. }
  6960. sstr[c] = '\0';
  6961. strcpy(dataStr, sstr);
  6962. return result;
  6963. }
  6964. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6965. {
  6966. mtrace();
  6967. int result = FAIL;
  6968. char message[1000]={0};
  6969. int CompositeScheduleIndex = 0;
  6970. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6971. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6972. if(nPeriod == 0)
  6973. {
  6974. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6975. {
  6976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6977. ,MESSAGE_TYPE_CALLRESULT
  6978. ,uuid
  6979. ,payload
  6980. ,connectorIdInt);
  6981. }
  6982. else
  6983. {
  6984. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6985. ,MESSAGE_TYPE_CALLRESULT
  6986. ,uuid
  6987. ,payload
  6988. ,connectorIdInt
  6989. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6990. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6991. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6992. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6993. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6994. }
  6995. }
  6996. else
  6997. {
  6998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6999. ,MESSAGE_TYPE_CALLRESULT
  7000. ,uuid
  7001. ,payload
  7002. ,connectorIdInt
  7003. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7004. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7005. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7006. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7007. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7008. {
  7009. if (idx_sample == 0)
  7010. {
  7011. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7012. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7013. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7014. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7015. }
  7016. else
  7017. {
  7018. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7019. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7020. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7021. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7022. }
  7023. }
  7024. sprintf(message + strlen(message), "]}}]");
  7025. }
  7026. LWS_Send(message);
  7027. result = TRUE;
  7028. return result;
  7029. }
  7030. int sendGetConfigurationConfirmation(char *uuid)
  7031. {
  7032. mtrace();
  7033. int result = FAIL;
  7034. int MaxKeySupported = 0;
  7035. int sentConfigurationNumber= 0;
  7036. int sentunConfigurationNumber= 0;
  7037. char message[1024*10]={0};
  7038. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7039. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7040. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7041. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7042. ,MESSAGE_TYPE_CALLRESULT
  7043. ,uuid );
  7044. //configuration key
  7045. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7046. {
  7047. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7048. {
  7049. if (sentConfigurationNumber == 0)
  7050. {
  7051. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7052. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7053. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7054. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7055. }
  7056. else
  7057. {
  7058. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7059. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7060. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7061. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7062. }
  7063. sentConfigurationNumber = sentConfigurationNumber + 1;
  7064. }
  7065. }
  7066. sprintf(message + strlen(message), "]");
  7067. if(UnknownKeynum != 0)
  7068. {
  7069. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7070. //unkown key
  7071. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7072. {
  7073. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7074. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7075. if(sentunConfigurationNumber == 0)
  7076. {
  7077. sprintf(message + strlen(message), "\"%s\""
  7078. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7079. }
  7080. else
  7081. {
  7082. sprintf(message + strlen(message), ",\"%s\""
  7083. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7084. }
  7085. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7086. }
  7087. sprintf(message + strlen(message), "]");
  7088. }
  7089. sprintf(message + strlen(message), "}]");
  7090. LWS_Send(message);
  7091. return result;
  7092. }
  7093. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7094. {
  7095. mtrace();
  7096. int result = FAIL;
  7097. char message[400]={0};
  7098. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7099. if(strcmp(payload,"")==0)
  7100. {
  7101. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7102. }
  7103. else
  7104. {
  7105. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7106. }
  7107. LWS_Send(message);
  7108. result = TRUE;
  7109. return result;
  7110. }
  7111. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7112. {
  7113. mtrace();
  7114. int result = FAIL;
  7115. char message[80]={0};
  7116. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7117. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7118. LWS_Send(message);
  7119. result = TRUE;
  7120. return result;
  7121. }
  7122. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7123. {
  7124. mtrace();
  7125. int result = FAIL;
  7126. char message[80]={0};
  7127. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7128. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7129. LWS_Send(message);
  7130. result = TRUE;
  7131. return result;
  7132. }
  7133. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7134. {
  7135. mtrace();
  7136. int result = FAIL;
  7137. char message[80]={0};
  7138. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7139. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7140. LWS_Send(message);
  7141. result = TRUE;
  7142. return result;
  7143. }
  7144. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7145. {
  7146. mtrace();
  7147. int result = FAIL;
  7148. char message[80]={0};
  7149. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7150. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7151. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7152. LWS_Send(message);
  7153. result = TRUE;
  7154. return result;
  7155. }
  7156. int sendResetConfirmation(char *uuid,char *payload)
  7157. {
  7158. mtrace();
  7159. int result = FAIL;
  7160. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7161. char message[80]={0};
  7162. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7163. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7164. LWS_Send(message);
  7165. result = TRUE;
  7166. return result;
  7167. }
  7168. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7169. {
  7170. mtrace();
  7171. int result = FAIL;
  7172. char message[500]={0};
  7173. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7174. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7175. LWS_Send(message);
  7176. result = TRUE;
  7177. return result;
  7178. }
  7179. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7180. {
  7181. mtrace();
  7182. int result = FAIL;
  7183. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7184. char message[80]={0};
  7185. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7186. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7187. LWS_Send(message);
  7188. result = TRUE;
  7189. return result;
  7190. }
  7191. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7192. {
  7193. mtrace();
  7194. int result = FAIL;
  7195. char message[80]={0};
  7196. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7197. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7198. LWS_Send(message);
  7199. result = TRUE;
  7200. return result;
  7201. }
  7202. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7203. {
  7204. mtrace();
  7205. int result = FAIL;
  7206. char message[80]={0};
  7207. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7208. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7209. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7210. LWS_Send(message);
  7211. result = TRUE;
  7212. return result;
  7213. }
  7214. int sendUpdateFirmwareConfirmation(char *uuid)
  7215. {
  7216. mtrace();
  7217. int result = FAIL;
  7218. char message[60]={0};
  7219. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7220. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7221. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7222. LWS_Send(message);
  7223. result = TRUE;
  7224. return result;
  7225. }
  7226. int sendCertificateSignedConfirmation(char *uuid)
  7227. {
  7228. mtrace();
  7229. int result = PASS;
  7230. char message[4096]={0};
  7231. json_object *CertificateSigned = json_object_new_object();
  7232. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7233. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7234. sprintf(message,"[%d,\"%s\",%s]"
  7235. ,MESSAGE_TYPE_CALLRESULT
  7236. ,uuid
  7237. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7238. json_object_put(CertificateSigned);
  7239. LWS_Send(message);
  7240. return result;
  7241. }
  7242. int sendDeleteCertificateConfirmation(char *uuid)
  7243. {
  7244. mtrace();
  7245. int result = PASS;
  7246. char message[4096]={0};
  7247. json_object *DeleteCertificate = json_object_new_object();
  7248. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7249. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7250. sprintf(message,"[%d,\"%s\",%s]"
  7251. ,MESSAGE_TYPE_CALLRESULT
  7252. ,uuid
  7253. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7254. json_object_put(DeleteCertificate);
  7255. LWS_Send(message);
  7256. return result;
  7257. }
  7258. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7259. {
  7260. mtrace();
  7261. int result = PASS;
  7262. char message[4096]={0};
  7263. json_object *ExtendedTriggerMessage = json_object_new_object();
  7264. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7265. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7266. sprintf(message,"[%d,\"%s\",%s]"
  7267. ,MESSAGE_TYPE_CALLRESULT
  7268. ,uuid
  7269. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7270. json_object_put(ExtendedTriggerMessage);
  7271. LWS_Send(message);
  7272. return result;
  7273. }
  7274. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7275. {
  7276. mtrace();
  7277. int result = PASS;
  7278. char message[4096]={0};
  7279. json_object *GetInstalledCertificateIds = json_object_new_object();
  7280. json_object *certificateHashDataDatas = json_object_new_array();
  7281. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7282. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7283. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7284. {
  7285. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7286. {
  7287. json_object *certificateHashData = json_object_new_object();
  7288. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7289. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7290. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7291. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7292. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7293. }
  7294. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7295. }
  7296. else
  7297. {
  7298. json_object_put(certificateHashDataDatas);
  7299. }
  7300. sprintf(message,"[%d,\"%s\",%s]"
  7301. ,MESSAGE_TYPE_CALLRESULT
  7302. ,uuid
  7303. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7304. json_object_put(GetInstalledCertificateIds);
  7305. LWS_Send(message);
  7306. return result;
  7307. }
  7308. int sendGetLogConfirmation(char *uuid)
  7309. {
  7310. mtrace();
  7311. int result = PASS;
  7312. char message[4096]={0};
  7313. json_object *GetLog = json_object_new_object();
  7314. DEBUG_INFO("sendGetLogConfirmation...\n");
  7315. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7316. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7317. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7318. sprintf(message,"[%d,\"%s\",%s]"
  7319. ,MESSAGE_TYPE_CALLRESULT
  7320. ,uuid
  7321. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7322. json_object_put(GetLog);
  7323. LWS_Send(message);
  7324. return result;
  7325. }
  7326. int sendInstallCertificateConfirmation(char *uuid)
  7327. {
  7328. mtrace();
  7329. int result = PASS;
  7330. char message[4096]={0};
  7331. json_object *InstallCertificate = json_object_new_object();
  7332. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7333. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7334. sprintf(message,"[%d,\"%s\",%s]"
  7335. ,MESSAGE_TYPE_CALLRESULT
  7336. ,uuid
  7337. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7338. json_object_put(InstallCertificate);
  7339. LWS_Send(message);
  7340. return result;
  7341. }
  7342. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7343. {
  7344. mtrace();
  7345. int result = PASS;
  7346. char message[4096]={0};
  7347. json_object *SignedUpdateFirmware = json_object_new_object();
  7348. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7349. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7350. sprintf(message,"[%d,\"%s\",%s]"
  7351. ,MESSAGE_TYPE_CALLRESULT
  7352. ,uuid
  7353. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7354. json_object_put(SignedUpdateFirmware);
  7355. LWS_Send(message);
  7356. return result;
  7357. }
  7358. int sendUnknownConfirmation(char *uuid)
  7359. {
  7360. mtrace();
  7361. int result = PASS;
  7362. char message[256]={0};
  7363. DEBUG_INFO("sendUnknownConfirmation...\n");
  7364. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7365. LWS_Send(message);
  7366. return result;
  7367. }
  7368. //==========================================
  7369. // Handle server request routine Start
  7370. //==========================================
  7371. int handleCancelReservationRequest(char *uuid, char *payload)
  7372. {
  7373. mtrace();
  7374. int result = FAIL;
  7375. int gunNO = 0;
  7376. int reservationIdInt = -1;
  7377. char comfirmstr[20];
  7378. DEBUG_INFO("handleCancelReservationRequest...\n");
  7379. json_object *CancelReservation;
  7380. CancelReservation = json_tokener_parse(payload);
  7381. if(!is_error(CancelReservation))
  7382. {
  7383. // Required data
  7384. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7385. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7386. }
  7387. json_object_put(CancelReservation);
  7388. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7389. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7390. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7391. if(reservationIdInt != -1)
  7392. {
  7393. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7394. //check Transaction active
  7395. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7397. {
  7398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7399. {
  7400. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7401. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7402. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7403. {
  7404. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7405. }
  7406. else
  7407. {
  7408. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7409. }
  7410. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7411. goto end;
  7412. }
  7413. }
  7414. for (int index = 0; index < CCS_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7417. {
  7418. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7419. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7420. if(gunType[2] == GUN_TYPE_CCS)
  7421. {
  7422. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7423. }
  7424. else
  7425. {
  7426. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7427. }
  7428. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7429. goto end;
  7430. }
  7431. }
  7432. for (int index = 0; index < GB_QUANTITY; index++)
  7433. {
  7434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7435. {
  7436. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7437. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7438. if(gunType[2] == GUN_TYPE_GBT)
  7439. {
  7440. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7441. }
  7442. else
  7443. {
  7444. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7445. }
  7446. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7447. goto end;
  7448. }
  7449. }
  7450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7451. {
  7452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7453. {
  7454. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7455. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7456. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7457. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7458. goto end;
  7459. }
  7460. }
  7461. for (int index = 0; index < AC_QUANTITY; index++)
  7462. {
  7463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7464. {
  7465. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7466. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7468. {
  7469. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7470. }
  7471. else
  7472. {
  7473. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7474. }
  7475. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7476. goto end;
  7477. }
  7478. }
  7479. }
  7480. //The reservationId does NOT match the reservationId
  7481. sendCancelReservationConfirmation(uuid, comfirmstr);
  7482. end:
  7483. // Fill in ocpp packet uuid
  7484. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7485. return result;
  7486. }
  7487. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7488. {
  7489. mtrace();
  7490. int result = FAIL;
  7491. int gunIndex = -1;
  7492. char typeStr[16]={0};
  7493. char comfirmstr[20];
  7494. int specificId = FALSE;
  7495. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7496. json_object *ChangeAvailability;
  7497. ChangeAvailability = json_tokener_parse(payload);
  7498. if(!is_error(ChangeAvailability))
  7499. {
  7500. // Required data
  7501. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7502. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7503. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7504. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7505. }
  7506. json_object_put(ChangeAvailability);
  7507. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7508. {
  7509. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7510. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7511. }
  7512. else if(gunIndex == 0)
  7513. {
  7514. for(int i=0; i < gunTotalNumber; i++)
  7515. {
  7516. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7517. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7518. }
  7519. }
  7520. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7522. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7523. {
  7524. specificId = TRUE;
  7525. }
  7526. if(specificId == FALSE)
  7527. goto end;
  7528. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7529. {
  7530. //----------------------gunIndex is 0 ------------------------------------------------//
  7531. if(gunIndex == 0)
  7532. {
  7533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7534. {
  7535. for(int i=0; i < gunTotalNumber; i++)
  7536. {
  7537. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7538. {
  7539. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7540. {
  7541. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7542. {
  7543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7544. goto end;
  7545. }
  7546. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7547. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7548. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7549. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7550. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7551. {
  7552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7553. goto end;
  7554. }
  7555. }
  7556. }//END FOR CHAdeMO_QUANTITY
  7557. for (int index = 0; index < CCS_QUANTITY; index++)
  7558. {
  7559. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7560. {
  7561. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7562. {
  7563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7564. goto end;
  7565. }
  7566. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7567. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7569. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7571. {
  7572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7573. goto end;
  7574. }
  7575. }
  7576. }//END FOR CCS_QUANTITY
  7577. for (int index = 0; index < GB_QUANTITY; index++)
  7578. {
  7579. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7580. {
  7581. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7582. {
  7583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7584. goto end;
  7585. }
  7586. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7590. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7591. {
  7592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7593. goto end;
  7594. }
  7595. }
  7596. }// END FOR GB_QUANTITY
  7597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7598. {
  7599. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7600. {
  7601. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7602. {
  7603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7604. goto end;
  7605. }
  7606. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7610. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7611. {
  7612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7613. goto end;
  7614. }
  7615. }
  7616. }// END FOR GENERAL_GUN_QUANTITY
  7617. for (int index = 0; index < AC_QUANTITY; index++)
  7618. {
  7619. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7620. {
  7621. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7622. {
  7623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7624. goto end;
  7625. }
  7626. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7629. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7631. {
  7632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7633. goto end;
  7634. }
  7635. }
  7636. }//END FOR AC_QUANTITY
  7637. }// END FOR gunTotalNumber
  7638. }
  7639. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7640. {
  7641. for(int i=0; i < gunTotalNumber; i++)
  7642. {
  7643. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7644. {
  7645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7646. goto end;
  7647. }
  7648. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7652. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7653. {
  7654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7655. goto end;
  7656. }
  7657. }
  7658. }
  7659. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7660. goto end;
  7661. }
  7662. //----------------------gunIndex is not 0 ------------------------------------------------//
  7663. //check Transaction active
  7664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7665. {
  7666. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7667. {
  7668. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7669. {
  7670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7671. goto end;
  7672. }
  7673. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7678. {
  7679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7680. goto end;
  7681. }
  7682. else
  7683. {
  7684. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7686. goto end;
  7687. }
  7688. }
  7689. }//END FOR CHAdeMO_QUANTITY
  7690. for (int index = 0; index < CCS_QUANTITY; index++)
  7691. {
  7692. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7693. {
  7694. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7695. {
  7696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7697. goto end;
  7698. }
  7699. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7701. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7702. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7703. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7704. {
  7705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7706. goto end;
  7707. }
  7708. else
  7709. {
  7710. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7712. goto end;
  7713. }
  7714. }
  7715. }//END FOR CCS_QUANTITY
  7716. for (int index = 0; index < GB_QUANTITY; index++)
  7717. {
  7718. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7719. {
  7720. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7721. {
  7722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7723. goto end;
  7724. }
  7725. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7727. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7728. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7729. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7730. {
  7731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7732. goto end;
  7733. }
  7734. else
  7735. {
  7736. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7738. goto end;
  7739. }
  7740. }
  7741. }// END FOR GB_QUANTITY
  7742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7743. {
  7744. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7745. {
  7746. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7747. {
  7748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7749. goto end;
  7750. }
  7751. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7756. {
  7757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7758. goto end;
  7759. }
  7760. else
  7761. {
  7762. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7763. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7764. goto end;
  7765. }
  7766. }
  7767. }// END FOR GENERAL_GUN_QUANTITY
  7768. for (int index = 0; index < AC_QUANTITY; index++)
  7769. {
  7770. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7771. {
  7772. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7773. {
  7774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7775. goto end;
  7776. }
  7777. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7780. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7781. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7782. {
  7783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7784. goto end;
  7785. }
  7786. else
  7787. {
  7788. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7789. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7790. goto end;
  7791. }
  7792. }
  7793. }//END FOR AC_QUANTITY
  7794. }//END FOR AvailabilityTypeStr[Inoperative]
  7795. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7796. {
  7797. //----------------------gunIndex is 0 ------------------------------------------------//
  7798. if(gunIndex == 0)
  7799. {
  7800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7801. {
  7802. for(int i=0; i < gunTotalNumber; i++)
  7803. {
  7804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7805. {
  7806. 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
  7807. {
  7808. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7809. goto end;
  7810. }
  7811. }//END FOR CHAdeMO_QUANTITY
  7812. for (int index = 0; index < CCS_QUANTITY; index++)
  7813. {
  7814. 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
  7815. {
  7816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7817. goto end;
  7818. }
  7819. }//END FOR CCS_QUANTITY
  7820. for (int index = 0; index < GB_QUANTITY; index++)
  7821. {
  7822. 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
  7823. {
  7824. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7826. goto end;
  7827. }
  7828. }// END FOR GB_QUANTITY
  7829. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7830. {
  7831. 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
  7832. {
  7833. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7835. goto end;
  7836. }
  7837. }// END FOR GENERAL_GUN_QUANTITY
  7838. for (int index = 0; index < AC_QUANTITY; index++)
  7839. {
  7840. 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
  7841. {
  7842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7843. goto end;
  7844. }
  7845. }//END FOR CHAdeMO_QUANTITY
  7846. }// END FOR gunTotalNumber
  7847. }
  7848. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7849. {
  7850. for(int i=0; i < gunTotalNumber; i++)
  7851. {
  7852. for (int index = 0; index < AC_QUANTITY; index++)
  7853. {
  7854. 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
  7855. {
  7856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7857. goto end;
  7858. }
  7859. }//END FOR CHAdeMO_QUANTITY
  7860. } // END FOR gunTotalNumber
  7861. }
  7862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7863. goto end;
  7864. }
  7865. //----------------------gunIndex is not 0 ------------------------------------------------//
  7866. //check Transaction active
  7867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7868. {
  7869. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7870. {
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7872. goto end;
  7873. }
  7874. }//END FOR CHAdeMO_QUANTITY
  7875. for (int index = 0; index < CCS_QUANTITY; index++)
  7876. {
  7877. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7878. {
  7879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7880. goto end;
  7881. }
  7882. }//END FOR CCS_QUANTITY
  7883. for (int index = 0; index < GB_QUANTITY; index++)
  7884. {
  7885. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7886. {
  7887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7888. goto end;
  7889. }
  7890. }// END FOR GB_QUANTITY
  7891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7892. {
  7893. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7894. {
  7895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7896. goto end;
  7897. }
  7898. }// END FOR GENERAL_GUN_QUANTITY
  7899. for (int index = 0; index < AC_QUANTITY; index++)
  7900. {
  7901. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7902. {
  7903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7904. goto end;
  7905. }
  7906. }//END FOR AC_QUANTITY
  7907. }//END FOR AvailabilityTypeStr[Operative]
  7908. end:
  7909. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7910. {
  7911. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7912. }
  7913. else
  7914. {
  7915. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7916. }
  7917. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7918. {
  7919. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7920. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7921. }
  7922. else if(gunIndex == 0)
  7923. {
  7924. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7925. {
  7926. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7927. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7928. }
  7929. }
  7930. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7931. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7932. return result;
  7933. }
  7934. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7935. {
  7936. mtrace();
  7937. int result = FAIL;
  7938. char keystr[40]={0};
  7939. char valuestr[501]={0}; //value should be limited in 500 bytes
  7940. char comfirmstr[20]={0};
  7941. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7942. json_object *ChangeConfiguration;
  7943. ChangeConfiguration = json_tokener_parse(payload);
  7944. if(!is_error(ChangeConfiguration))
  7945. {
  7946. // Required data
  7947. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7948. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7949. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  7950. {
  7951. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7952. }
  7953. else
  7954. {
  7955. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  7956. }
  7957. }
  7958. json_object_put(ChangeConfiguration);
  7959. if((uuid==NULL) || (payload ==NULL) || (strlen(valuestr)<=0))
  7960. {
  7961. DEBUG_ERROR("Payload is null or not accepted.\n");
  7962. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7963. }
  7964. else
  7965. {
  7966. int status = setKeyValue(keystr, valuestr);
  7967. switch(status)
  7968. {
  7969. case ConfigurationStatus_Accepted:
  7970. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7971. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7972. StoreConfigurationTable();
  7973. break;
  7974. case RebootRequired:
  7975. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7976. StoreConfigurationTable();
  7977. break;
  7978. case NotSupported:
  7979. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7980. break;
  7981. case ConfigurationStatus_Rejected:
  7982. default:
  7983. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7984. break;
  7985. }
  7986. }
  7987. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7988. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7989. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7990. {
  7991. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7992. SetOcppConnStatus(FALSE);
  7993. }
  7994. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7995. {
  7996. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7997. }
  7998. return result;
  7999. }
  8000. int handleClearCacheRequest(char *uuid, char *payload)
  8001. {
  8002. mtrace();
  8003. int result = FAIL;
  8004. char comfirmstr[20];
  8005. char rmFileCmd[100]={0};
  8006. struct stat stats;
  8007. DEBUG_INFO("handleClearCacheRequest...\n");
  8008. stat("/Storage/OCPP_PH", &stats);
  8009. // Check for directory existence
  8010. if (S_ISDIR(stats.st_mode) == 1)
  8011. {}
  8012. else
  8013. {
  8014. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8015. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8016. system(rmFileCmd);
  8017. }
  8018. if(OCPP_cleanLocalCache())
  8019. {
  8020. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8021. }
  8022. else
  8023. {
  8024. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8025. }
  8026. sendClearCacheConfirmation(uuid, comfirmstr);
  8027. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8028. return result;
  8029. }
  8030. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8031. {
  8032. mtrace();
  8033. int result = FAIL;
  8034. int resultRename;
  8035. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8036. char chargingProfilePurposeStr[26]={0};
  8037. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8038. char tempchargingProfilePurposeStr[26]={0};
  8039. char str[100]={0};
  8040. char fname[200]={0};
  8041. char comfirmstr[20]={0};
  8042. char word[1600]={0};
  8043. int clearflag = FALSE;
  8044. int chargingProfileIdIsNULL = FALSE;
  8045. int connectorIsNULL = FALSE;
  8046. int chargingProfilePurposeIsNULL = FALSE;
  8047. int stackLevelIsNULL = FALSE;
  8048. //int GotoEnd = FALSE;
  8049. FILE *fptr1, *fptr2;
  8050. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8051. int n_chargingProfile=0;
  8052. int isEmptyFile = FALSE;
  8053. char sLineWord[1600]={0};
  8054. char chargingProfiles[10][100]={0};
  8055. int ChargeProfileCount = 0;
  8056. int ch;
  8057. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8058. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8059. json_object *ClearChargingProfile;
  8060. ClearChargingProfile = json_tokener_parse(payload);
  8061. if(!is_error(ClearChargingProfile))
  8062. {
  8063. // Optional data
  8064. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8065. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8066. else
  8067. chargingProfileIdIsNULL = TRUE;
  8068. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8069. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8070. else
  8071. connectorIsNULL = TRUE;
  8072. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8073. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8074. else
  8075. chargingProfilePurposeIsNULL = TRUE;
  8076. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8077. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8078. else
  8079. stackLevelIsNULL = TRUE;
  8080. }
  8081. json_object_put(ClearChargingProfile);
  8082. if(connectorIsNULL == FALSE)
  8083. {
  8084. switch(connectorIdInt)
  8085. {
  8086. case 0:
  8087. if(chargingProfilePurposeIsNULL == TRUE)
  8088. {
  8089. int l = 0;
  8090. strcpy(fname, ChargePointMaxProfile_JSON);
  8091. if((access(fname,F_OK))!=-1)
  8092. {
  8093. strcpy(chargingProfiles[l], fname);
  8094. l = l + 1;
  8095. }
  8096. strcpy(fname, TxDefaultProfile_0_JSON);
  8097. if((access(fname,F_OK))!=-1)
  8098. {
  8099. strcpy(chargingProfiles[l], fname);
  8100. l = l + 1;
  8101. }
  8102. ChargeProfileCount = l;
  8103. }
  8104. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8105. {
  8106. strcpy(fname, ChargePointMaxProfile_JSON);
  8107. if((access(fname,F_OK))!=-1)
  8108. {
  8109. strcpy(chargingProfiles[0], fname);
  8110. ChargeProfileCount = 1;
  8111. }
  8112. }
  8113. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8114. {
  8115. strcpy(fname, TxDefaultProfile_0_JSON);
  8116. if((access(fname,F_OK))!=-1)
  8117. {
  8118. strcpy(chargingProfiles[0], fname);
  8119. ChargeProfileCount = 1;
  8120. }
  8121. }
  8122. break;
  8123. default:
  8124. if(chargingProfilePurposeIsNULL == TRUE)
  8125. {
  8126. int m = 0;
  8127. memset(fname, 0, ARRAY_SIZE(fname));
  8128. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8129. if((access(fname,F_OK))!=-1)
  8130. {
  8131. strcpy(chargingProfiles[m], fname);
  8132. m = m + 1;
  8133. }
  8134. memset(fname, 0, ARRAY_SIZE(fname));
  8135. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8136. if((access(fname,F_OK))!=-1)
  8137. {
  8138. strcpy(chargingProfiles[m], fname);
  8139. m = m + 1;
  8140. }
  8141. ChargeProfileCount = m;
  8142. }
  8143. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8144. {
  8145. //strcpy(fname, TxDefaultProfile_1_JSON);
  8146. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8147. if((access(fname,F_OK))!=-1)
  8148. {
  8149. strcpy(chargingProfiles[0], fname);
  8150. ChargeProfileCount = 1;
  8151. }
  8152. }
  8153. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8154. {
  8155. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8156. if((access(fname,F_OK))!=-1)
  8157. {
  8158. strcpy(chargingProfiles[0], fname);
  8159. ChargeProfileCount = 1;
  8160. }
  8161. //strcpy(fname, TxProfile_1_JSON);
  8162. }
  8163. //strcpy(fname, ChargePointMaxProfile_JSON );
  8164. break;
  8165. }
  8166. }
  8167. else // Check all Charging Profiles
  8168. {
  8169. int i = 0;
  8170. char fnametemp[200]={0};
  8171. ChargeProfileCount = 0;
  8172. //Check ChargePointMaxProfile.json exit
  8173. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8174. {
  8175. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8176. i = i + 1;
  8177. }
  8178. //Check TxDefaultProfile_0.json exit
  8179. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8180. {
  8181. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8182. i = i + 1;
  8183. }
  8184. //Check TxDefaultProfile_%d.json
  8185. for(int j=1; j <= gunTotalNumber; j++)
  8186. {
  8187. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8188. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8189. if((access(fnametemp,F_OK))!=-1)
  8190. {
  8191. strcpy(chargingProfiles[i], fnametemp);
  8192. i = i + 1;
  8193. }
  8194. }
  8195. //Check TxProfile_%d.json
  8196. for(int j=1; j <= gunTotalNumber; j++)
  8197. {
  8198. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8199. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8200. if((access(fnametemp,F_OK))!=-1)
  8201. {
  8202. strcpy(chargingProfiles[i], fnametemp);
  8203. i = i + 1;
  8204. }
  8205. }
  8206. ChargeProfileCount = i;
  8207. }// End connectorIsNULL is TRUE
  8208. if(ChargeProfileCount == 0)
  8209. {
  8210. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8211. goto end;
  8212. }
  8213. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8214. {
  8215. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8216. goto end;
  8217. }
  8218. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8219. {
  8220. memset(str, 0, ARRAY_SIZE(str));
  8221. // clear temp file
  8222. sprintf(str,"rm -f %s",temp);
  8223. system(str);
  8224. for(int k=0; k < ChargeProfileCount; k++)
  8225. {
  8226. memset(str, 0, ARRAY_SIZE(str));
  8227. //clear file in C
  8228. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8229. system(str);
  8230. }
  8231. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8232. goto end;
  8233. }
  8234. else if(connectorIsNULL == TRUE)
  8235. {
  8236. for(int k=0; k < ChargeProfileCount; k++)
  8237. {
  8238. fptr1 = fopen(chargingProfiles[k], "r");
  8239. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8240. //Check Charging Profile Count
  8241. while(fscanf(fptr1, "%s", word) != EOF)
  8242. {
  8243. //DEBUG_INFO("word=%s\n",word);
  8244. if(strstr(word, "chargingProfileId")!= NULL)
  8245. {
  8246. //DEBUG_INFO("test chargingProfileId \n");
  8247. n_chargingProfile = n_chargingProfile + 1;
  8248. //DEBUG_INFO("chargingProfileId Found\n");
  8249. }
  8250. }
  8251. rewind(fptr1);
  8252. //search Charging Profile Element
  8253. //int i= 0;
  8254. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8255. {
  8256. json_object *tmpProfilee;
  8257. tmpProfilee = json_tokener_parse(sLineWord);
  8258. if(!is_error(tmpProfilee))
  8259. {
  8260. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8261. {
  8262. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8263. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8264. }
  8265. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8266. {
  8267. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8268. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8269. }
  8270. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8271. {
  8272. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8273. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8274. }
  8275. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8276. {
  8277. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8278. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8279. }
  8280. }
  8281. json_object_put(tmpProfilee);
  8282. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8283. {
  8284. //------- not write to fptr2-------//
  8285. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8286. //clearflag = TRUE;
  8287. }
  8288. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8289. {
  8290. //------- not write to fptr2-------//
  8291. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8292. }
  8293. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8294. {
  8295. //------- not write to fptr2-------//
  8296. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8297. }
  8298. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8299. {
  8300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8301. }
  8302. else
  8303. {
  8304. fprintf(fptr2, sLineWord);//writing data into file
  8305. }
  8306. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8307. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8308. if(clearflag == TRUE)
  8309. {
  8310. fclose(fptr1);
  8311. fclose(fptr2);
  8312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8313. system(str);
  8314. // clear temp file
  8315. sprintf(str,"rm -f %s",temp);
  8316. system(str);
  8317. }
  8318. else
  8319. {
  8320. fclose(fptr1);
  8321. fclose(fptr2);
  8322. memset(str, 0, ARRAY_SIZE(str));
  8323. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8324. system(str);
  8325. resultRename = rename(temp, chargingProfiles[k]);
  8326. if(resultRename == 0)
  8327. {
  8328. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8329. }
  8330. else
  8331. {
  8332. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8333. }
  8334. if(comfirmstr[0]== 0)
  8335. {
  8336. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8337. }
  8338. //Check chargingProfile is empty file
  8339. /*------ Read the file ----------------*/
  8340. fptr1=fopen(chargingProfiles[k],"r");
  8341. ch=fgetc(fptr1);
  8342. rewind(fptr1);
  8343. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8344. if(ch!=EOF)
  8345. {
  8346. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8347. {
  8348. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8349. if(sLineWord[0]=='\0')
  8350. {
  8351. isEmptyFile = TRUE;
  8352. break;
  8353. }
  8354. else
  8355. {
  8356. isEmptyFile = FALSE;
  8357. break;
  8358. }
  8359. }
  8360. }
  8361. else
  8362. isEmptyFile = TRUE;
  8363. fclose(fptr1);
  8364. if(isEmptyFile == TRUE)
  8365. {
  8366. memset(str, 0, ARRAY_SIZE(str));
  8367. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8368. system(str);
  8369. }
  8370. }
  8371. }// End of while(int k=0; k < ChargePointCount; k++)
  8372. }
  8373. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8374. {
  8375. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8376. for(int k=0; k < ChargeProfileCount; k++)
  8377. {
  8378. fptr1 = fopen(chargingProfiles[k], "r");
  8379. fptr2 = fopen(temp, "w+");
  8380. //Check Charging Profile Count
  8381. while(fscanf(fptr1, "%s", word) != EOF)
  8382. {
  8383. //DEBUG_INFO("word=%s\n",word);
  8384. if(strstr(word, "chargingProfileId")!= NULL)
  8385. {
  8386. n_chargingProfile = n_chargingProfile + 1;
  8387. }
  8388. }
  8389. rewind(fptr1);
  8390. //search Charging Profile Element
  8391. //int i= 0;
  8392. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8393. {
  8394. json_object *tmpProfilee;
  8395. tmpProfilee = json_tokener_parse(sLineWord);
  8396. if(!is_error(tmpProfilee))
  8397. {
  8398. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8399. {
  8400. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8401. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8402. }
  8403. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8404. {
  8405. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8406. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8407. }
  8408. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8409. {
  8410. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8411. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8412. }
  8413. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8414. {
  8415. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8416. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8417. }
  8418. }
  8419. json_object_put(tmpProfilee);
  8420. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8421. {
  8422. //------- not write to fptr2-------//
  8423. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8424. //clearflag = TRUE;
  8425. }
  8426. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8427. {
  8428. //------- not write to fptr2-------//
  8429. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8430. }
  8431. else if(stackLevelIsNULL == TRUE)
  8432. {
  8433. //Clear Whole File
  8434. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8435. clearflag = TRUE;
  8436. break;
  8437. }
  8438. else
  8439. {
  8440. fprintf(fptr2, sLineWord);//writing data into file
  8441. }
  8442. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8443. }
  8444. if(clearflag == TRUE)
  8445. {
  8446. fclose(fptr1);
  8447. fclose(fptr2);
  8448. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8449. system(str);
  8450. // clear temp file
  8451. sprintf(str,"rm -f %s",temp);
  8452. system(str);
  8453. }
  8454. else
  8455. {
  8456. fclose(fptr1);
  8457. fclose(fptr2);
  8458. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8459. system(str);
  8460. resultRename = rename(temp, chargingProfiles[k]);
  8461. if(resultRename == 0)
  8462. {
  8463. DEBUG_INFO("File ChargingProfile renamed successfully");
  8464. }
  8465. else
  8466. {
  8467. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8468. }
  8469. if(comfirmstr[0]== 0)
  8470. {
  8471. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8472. }
  8473. //Check chargingProfile is empty file
  8474. /*------ Read the file ----------------*/
  8475. fptr1=fopen(chargingProfiles[k],"r");
  8476. ch=fgetc(fptr1);
  8477. rewind(fptr1);
  8478. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8479. if(ch!=EOF)
  8480. {
  8481. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8482. {
  8483. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8484. if(sLineWord[0]=='\0')
  8485. {
  8486. isEmptyFile = TRUE;
  8487. break;
  8488. }
  8489. else
  8490. {
  8491. isEmptyFile = FALSE;
  8492. break;
  8493. }
  8494. }
  8495. }
  8496. else
  8497. isEmptyFile = TRUE;
  8498. fclose(fptr1);
  8499. if(isEmptyFile == TRUE)
  8500. {
  8501. memset(str, 0, ARRAY_SIZE(str));
  8502. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8503. system(str);
  8504. }
  8505. /*------- End of reading ---------------*/
  8506. }
  8507. } // while(int k=0; k < ChargeProfileCount; k++)
  8508. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8509. end:
  8510. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8511. {
  8512. if(connectorIdInt == 0)
  8513. {
  8514. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8515. {
  8516. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8517. }
  8518. }
  8519. else
  8520. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8521. }
  8522. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8523. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8524. return result;
  8525. }
  8526. void createFirmwareVersionByDataTransfer(void)
  8527. {
  8528. json_object *FirmwareDataTransfer = json_object_new_object();
  8529. // AC & DC model
  8530. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8531. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8532. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8533. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8534. // DC model
  8535. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8536. {
  8537. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8538. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8539. (gunType[3] != GUN_TYPE_UNKNOWN))
  8540. {
  8541. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8542. }
  8543. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8544. {
  8545. // DS DM DW
  8546. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8547. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8548. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8549. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8550. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8551. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8552. }
  8553. else
  8554. {
  8555. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8556. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8557. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8558. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8559. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8560. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8561. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8562. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8563. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8564. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8565. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8566. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8567. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8568. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8569. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8570. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8571. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8573. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8575. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8577. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8579. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8581. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8582. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8583. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8584. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8585. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8586. }
  8587. }
  8588. // 4G model
  8589. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8590. {
  8591. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8592. }
  8593. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8594. json_object_put(FirmwareDataTransfer);
  8595. }
  8596. int handleDataTransferRequest(char *uuid, char *payload)
  8597. {
  8598. mtrace();
  8599. json_object *response = json_object_new_object();
  8600. int result = FAIL;
  8601. char tempvendorId[255]={0};
  8602. char tempmessageId[50]={0};
  8603. char tempdata[512]={0};
  8604. char message[2048]={0};
  8605. DEBUG_INFO("handleDataTransferRequest...\n");
  8606. if((uuid != NULL) && (payload != NULL))
  8607. {
  8608. json_object *DataTransfer;
  8609. DataTransfer = json_tokener_parse(payload);
  8610. if(!is_error(DataTransfer))
  8611. {
  8612. // Required data
  8613. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8614. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8615. // Optional data
  8616. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8617. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8618. if(json_object_object_get(DataTransfer, "data") != NULL)
  8619. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8620. result = PASS;
  8621. }
  8622. json_object_put(DataTransfer);
  8623. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8624. {
  8625. // Send all moudle firmware version on EVSE
  8626. createFirmwareVersionByDataTransfer();
  8627. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8628. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8629. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8630. json_object_put(response);
  8631. }
  8632. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8633. {
  8634. system("/usr/bin/run_tmate_restart.sh &");
  8635. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8636. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8637. json_object_put(response);
  8638. }
  8639. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8640. {
  8641. json_object *data;
  8642. data = json_tokener_parse(tempdata);
  8643. if(!is_error(data))
  8644. {
  8645. 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))
  8646. {
  8647. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8648. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8649. if(json_object_object_get(data, "SOC") != NULL)
  8650. {
  8651. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8652. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8653. }
  8654. if(json_object_object_get(data, "Energy") != NULL)
  8655. {
  8656. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8657. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8658. }
  8659. if(json_object_object_get(data, "Duration") != NULL)
  8660. {
  8661. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8662. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8663. }
  8664. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8665. }
  8666. else
  8667. {
  8668. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8669. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8670. }
  8671. }
  8672. else
  8673. {
  8674. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8675. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8676. }
  8677. json_object_put(data);
  8678. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8679. json_object_put(response);
  8680. }
  8681. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8682. {
  8683. json_object *data;
  8684. data = json_tokener_parse(tempdata);
  8685. if(!is_error(data))
  8686. {
  8687. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8688. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8689. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8690. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8691. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8692. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8693. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8694. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8695. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8696. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8697. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8698. }
  8699. else
  8700. {
  8701. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8702. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8703. }
  8704. json_object_put(data);
  8705. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8706. json_object_put(response);
  8707. }
  8708. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8709. {
  8710. json_object *data;
  8711. data = json_tokener_parse(tempdata);
  8712. if(!is_error(data))
  8713. {
  8714. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8715. if(json_object_object_get(data, "idToken") != NULL)
  8716. {
  8717. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8718. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8719. }
  8720. if(json_object_object_get(data, "price") != NULL)
  8721. {
  8722. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8723. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8724. }
  8725. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8726. }
  8727. else
  8728. {
  8729. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8730. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8731. }
  8732. json_object_put(data);
  8733. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8734. json_object_put(response);
  8735. }
  8736. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8737. {
  8738. json_object *data;
  8739. data = json_tokener_parse(tempdata);
  8740. if(!is_error(data))
  8741. {
  8742. if(json_object_object_get(data, "txId") != NULL)
  8743. {
  8744. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8745. for(int idx = 0;idx<gunTotalNumber;idx++)
  8746. {
  8747. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8748. {
  8749. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8750. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8751. if(json_object_object_get(data, "description") != NULL)
  8752. {
  8753. // California pricing V1.0
  8754. DEBUG_INFO("California pricing V1.0\n");
  8755. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8756. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8757. }
  8758. else
  8759. {
  8760. // California pricing V1.1
  8761. DEBUG_INFO("California pricing V1.1\n");
  8762. if(json_object_object_get(data, "timestamp") != NULL)
  8763. {
  8764. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8765. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8766. }
  8767. if(json_object_object_get(data, "meterValue") != NULL)
  8768. {
  8769. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8770. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8771. }
  8772. if(json_object_object_get(data, "cost") != NULL)
  8773. {
  8774. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8775. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8776. }
  8777. if(json_object_object_get(data, "state") != NULL)
  8778. {
  8779. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8780. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8781. }
  8782. if(json_object_object_get(data, "chargingPrice") != NULL)
  8783. {
  8784. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8785. {
  8786. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8787. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8788. }
  8789. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8790. {
  8791. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8792. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8793. }
  8794. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8795. {
  8796. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8797. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8798. }
  8799. }
  8800. if(json_object_object_get(data, "idlePrice") != NULL)
  8801. {
  8802. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8803. {
  8804. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8805. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8806. }
  8807. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8808. {
  8809. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8810. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8811. }
  8812. }
  8813. if(json_object_object_get(data, "nextPeriod") != NULL)
  8814. {
  8815. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8816. {
  8817. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8818. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8819. }
  8820. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8821. {
  8822. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8823. {
  8824. 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")));
  8825. 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"));
  8826. }
  8827. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8828. {
  8829. 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")));
  8830. 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"));
  8831. }
  8832. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8833. {
  8834. 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")));
  8835. 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"));
  8836. }
  8837. }
  8838. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8839. {
  8840. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8841. {
  8842. 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")));
  8843. 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"));
  8844. }
  8845. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8846. {
  8847. 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")));
  8848. 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"));
  8849. }
  8850. }
  8851. }
  8852. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8853. {
  8854. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8855. {
  8856. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8857. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8858. }
  8859. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8860. {
  8861. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8862. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8863. }
  8864. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8865. {
  8866. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8867. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8868. }
  8869. }
  8870. }
  8871. }
  8872. }
  8873. }
  8874. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8875. }
  8876. else
  8877. {
  8878. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8879. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8880. }
  8881. json_object_put(data);
  8882. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8883. json_object_put(response);
  8884. }
  8885. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8886. {
  8887. json_object *data;
  8888. data = json_tokener_parse(tempdata);
  8889. if(!is_error(data))
  8890. {
  8891. if(json_object_object_get(data, "txId") != NULL)
  8892. {
  8893. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8894. for(int idx = 0;idx<gunTotalNumber;idx++)
  8895. {
  8896. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8897. {
  8898. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8899. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8900. if(json_object_object_get(data, "description") != NULL)
  8901. {
  8902. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8903. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8904. }
  8905. }
  8906. }
  8907. }
  8908. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8909. }
  8910. else
  8911. {
  8912. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8913. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8914. }
  8915. json_object_put(data);
  8916. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8917. json_object_put(response);
  8918. }
  8919. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8920. {
  8921. json_object *data;
  8922. data = json_tokener_parse(tempdata);
  8923. if(!is_error(data))
  8924. {
  8925. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8926. if(json_object_object_get(data, "Content_Type") != NULL)
  8927. {
  8928. 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))
  8929. {
  8930. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8931. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8932. {
  8933. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8934. }
  8935. }
  8936. else
  8937. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8938. }
  8939. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8940. }
  8941. else
  8942. {
  8943. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8944. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8945. }
  8946. json_object_put(data);
  8947. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8948. json_object_put(response);
  8949. }
  8950. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8951. {
  8952. json_object *data;
  8953. data = json_tokener_parse(tempdata);
  8954. if(!is_error(data))
  8955. {
  8956. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8957. if(json_object_object_get(data, "Page_Index") != NULL)
  8958. {
  8959. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8960. }
  8961. if(json_object_object_get(data, "Duration") != NULL)
  8962. {
  8963. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8964. }
  8965. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8966. }
  8967. else
  8968. {
  8969. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8970. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8971. }
  8972. json_object_put(data);
  8973. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8974. json_object_put(response);
  8975. }
  8976. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8977. {
  8978. json_object *data;
  8979. data = json_tokener_parse(tempdata);
  8980. if(!is_error(data))
  8981. {
  8982. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8983. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8984. {
  8985. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8986. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8987. else
  8988. {
  8989. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8990. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8991. }
  8992. }
  8993. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8994. {
  8995. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8996. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8997. else
  8998. {
  8999. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9000. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9001. }
  9002. }
  9003. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9004. {
  9005. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9006. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9007. else
  9008. {
  9009. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9010. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9011. }
  9012. }
  9013. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9014. {
  9015. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9016. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9017. else
  9018. {
  9019. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9020. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9021. }
  9022. }
  9023. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9024. {
  9025. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9026. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9027. else
  9028. {
  9029. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9030. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9031. }
  9032. }
  9033. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9034. {
  9035. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9036. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9037. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9038. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9039. else
  9040. {
  9041. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9042. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9043. }
  9044. }
  9045. if(json_object_object_get(data, "isAuthentication") != NULL)
  9046. {
  9047. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9048. {
  9049. case 0:
  9050. case 1:
  9051. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9052. break;
  9053. default:
  9054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9055. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9056. break;
  9057. }
  9058. }
  9059. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9060. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9061. }
  9062. else
  9063. {
  9064. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9065. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9066. }
  9067. json_object_put(data);
  9068. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9069. json_object_put(response);
  9070. }
  9071. else
  9072. {
  9073. // Can not find valid message id
  9074. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9075. }
  9076. }
  9077. else
  9078. {
  9079. // Payload is null
  9080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9081. }
  9082. LWS_Send(message);
  9083. return result;
  9084. }
  9085. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9086. {
  9087. mtrace();
  9088. int result = FAIL;
  9089. int connectorIdInt, durationInt;
  9090. char chargingRateUnitStr[4]={0};
  9091. char comfirmstr[20];
  9092. int confirmPeriods = 0;
  9093. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9094. json_object *GetCompositeSchedule;
  9095. GetCompositeSchedule = json_tokener_parse(payload);
  9096. if(!is_error(GetCompositeSchedule))
  9097. {
  9098. // Required data
  9099. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9100. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9101. else
  9102. connectorIdInt = -1;
  9103. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9104. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9105. else
  9106. durationInt = 86400;
  9107. // Optional data
  9108. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9109. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9110. }
  9111. json_object_put(GetCompositeSchedule);
  9112. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9113. if((connectorIdInt == 0) ||
  9114. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9115. {
  9116. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9117. struct StructChargingProfile tmpProfile[1];
  9118. if(strstr(chargingRateUnitStr, "W") != NULL)
  9119. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9120. else
  9121. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9122. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9123. {
  9124. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9125. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9126. }
  9127. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9128. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9129. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9130. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9131. {
  9132. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9133. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9134. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9135. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9136. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9137. {
  9138. confirmPeriods = idx;
  9139. break;
  9140. }
  9141. }
  9142. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9143. {
  9144. confirmPeriods += 1;
  9145. }
  9146. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9147. }
  9148. else
  9149. {
  9150. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9151. }
  9152. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9153. return result;
  9154. }
  9155. int handleGetConfigurationRequest(char *uuid, char *payload)
  9156. {
  9157. mtrace();
  9158. int result = FAIL;
  9159. int MaxKeySupported = 0;
  9160. int n_keys = 0;
  9161. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9162. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9163. json_object *GetConfiguration;
  9164. GetConfiguration = json_tokener_parse(payload);
  9165. if(!is_error(GetConfiguration))
  9166. {
  9167. // Optional data
  9168. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9169. {
  9170. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9171. {
  9172. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9173. n_keys = idx + 1;
  9174. }
  9175. }
  9176. }
  9177. json_object_put(GetConfiguration);
  9178. UnknownKeynum = 0;
  9179. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9180. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9181. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9182. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9183. if(n_keys != 0)
  9184. {
  9185. for(int i=0;i<n_keys;i++)
  9186. {
  9187. getKeyValue(requestKey[i]);
  9188. }
  9189. }
  9190. else
  9191. {
  9192. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9193. getKeyValue("");
  9194. }
  9195. processUnkownKey();
  9196. sendGetConfigurationConfirmation(uuid);
  9197. return result;
  9198. }
  9199. static char fnamePlusPath[100]={0};
  9200. static char fnamePWithNoPath[60]={0};
  9201. void checkUploadLog(void)
  9202. {
  9203. FILE *fp;
  9204. /* Open the command for reading. */
  9205. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9206. if (fp == NULL) {
  9207. DEBUG_WARN("Failed to run command\n" );
  9208. exit(1);
  9209. }
  9210. int ftppathlen = 0;
  9211. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9212. int i = 0;
  9213. /* Read the output a line at a time - output it. */
  9214. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9215. if(i==0)
  9216. {
  9217. ftppathlen = strlen(fnamePlusPath);
  9218. DEBUG_INFO("%s\n", fnamePlusPath);
  9219. fnamePlusPath[ftppathlen]='\0';
  9220. break;
  9221. }
  9222. i= i+1;
  9223. }
  9224. /* close */
  9225. pclose(fp);
  9226. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9227. {
  9228. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9229. {
  9230. fnamePlusPath[k]='\0';
  9231. }
  9232. }
  9233. i=1;
  9234. //char fname[60]={0};
  9235. while(i < ftppathlen)
  9236. {
  9237. int len=ftppathlen-i;
  9238. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9239. {
  9240. DEBUG_INFO("compare '/' all right\n");
  9241. break;
  9242. }
  9243. i=i+1;
  9244. }
  9245. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9246. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9247. fnamePWithNoPath[i+1] = '\0';
  9248. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9249. {
  9250. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9251. {
  9252. fnamePWithNoPath[j]='\0';
  9253. }
  9254. }
  9255. FILE* fp1 = fopen(fnamePlusPath, "r");
  9256. if (fp1)
  9257. {
  9258. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9259. // file exists
  9260. fclose(fp1);
  9261. }
  9262. else
  9263. {
  9264. // file doesn't exist
  9265. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9266. }
  9267. }
  9268. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9269. {
  9270. mtrace();
  9271. int result = FAIL;
  9272. time_t CurrentTime;
  9273. struct tm *tm;
  9274. pthread_t th_Status;
  9275. CurrentTime = time(NULL);
  9276. tm = localtime(&CurrentTime);
  9277. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9278. 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);
  9279. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9280. if(!interLock.isGetDiagnosticGoing)
  9281. {
  9282. interLock.isGetDiagnosticGoing = 1;
  9283. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9284. sleep(1);
  9285. }
  9286. else
  9287. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9288. return result;
  9289. }
  9290. void* GetDiagnosticsProcess(void* data)
  9291. {
  9292. pthread_detach(pthread_self());
  9293. mtrace();
  9294. int retriesInt=0, retryIntervalInt=0;
  9295. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9296. 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};
  9297. int port=0;
  9298. int isSuccess = FALSE;
  9299. char ftpbuf[200]={0};
  9300. char cmdBuf[2048];
  9301. struct tm *tmNow;
  9302. time_t CurrentTime;
  9303. struct tm tmStart;
  9304. struct tm tmStop;
  9305. CurrentTime = time(NULL);
  9306. tmNow=localtime(&CurrentTime);
  9307. uint16_t targetYear, targetMonth;
  9308. json_object *GetDiagnostics;
  9309. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9310. GetDiagnostics = json_tokener_parse(data);
  9311. if(!is_error(GetDiagnostics))
  9312. {
  9313. // Required data
  9314. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9315. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9316. // Optional data
  9317. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9318. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9319. else
  9320. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9321. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9322. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9323. else
  9324. retryIntervalInt = 30;
  9325. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9326. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9327. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9328. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9329. }
  9330. json_object_put(GetDiagnostics);
  9331. // Pack log to compress file
  9332. 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) &&
  9333. (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))
  9334. {
  9335. // Pack system log
  9336. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9337. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9338. targetYear = tmStart.tm_year;
  9339. targetMonth = tmStart.tm_mon;
  9340. do
  9341. {
  9342. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9343. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9344. if(targetMonth+1>=13)
  9345. {
  9346. targetYear += 1;
  9347. targetMonth = 1;
  9348. }
  9349. else
  9350. {
  9351. targetMonth += 1;
  9352. }
  9353. }while((targetYear < (tmNow->tm_year+1900)) ||
  9354. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9355. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9356. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9357. system(cmdBuf);
  9358. // Pack charging & event log
  9359. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9360. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9361. targetYear = tmStart.tm_year;
  9362. targetMonth = tmStart.tm_mon;
  9363. do
  9364. {
  9365. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9366. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9367. if(targetMonth+1>=13)
  9368. {
  9369. targetYear += 1;
  9370. targetMonth = 1;
  9371. }
  9372. else
  9373. {
  9374. targetMonth += 1;
  9375. }
  9376. }while((targetYear < (tmNow->tm_year+1900)) ||
  9377. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9378. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9379. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9380. system(cmdBuf);
  9381. // Combine log file
  9382. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9383. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9384. }
  9385. else
  9386. {
  9387. system("exec /root/logPackTools 'log' 6");
  9388. }
  9389. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9390. system(cmdBuf);
  9391. checkUploadLog();
  9392. //****************location*******************/
  9393. if(strcmp(locationstr,"")==0)
  9394. {
  9395. DEBUG_INFO("location is <Empty>!\n");
  9396. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9397. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9398. goto end;
  9399. }
  9400. memset(protocol, 0, ARRAY_SIZE(protocol));
  9401. memset(user, 0, ARRAY_SIZE(user) );
  9402. memset(password, 0, ARRAY_SIZE(password));
  9403. memset(host, 0, ARRAY_SIZE(host));
  9404. memset(path, 0, ARRAY_SIZE(path));
  9405. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9406. memset(host1, 0, ARRAY_SIZE(host1));
  9407. memset(path1, 0, ARRAY_SIZE(path1));
  9408. /*location: ftp://user:password@host:port/path*/
  9409. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9410. if((access(fnamePlusPath,F_OK))!=-1)
  9411. {
  9412. DEBUG_INFO("fnamePlusPath exist.\n");
  9413. }
  9414. else
  9415. {
  9416. DEBUG_INFO("fnamePlusPath not exist!\n");
  9417. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9418. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9419. goto end;
  9420. }
  9421. if(strchr(locationstr,'@')==NULL)
  9422. {
  9423. sscanf(locationstr,
  9424. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9425. protocol, host, &port, path);
  9426. strcpy(user,"anonymous");
  9427. strcpy(password,"");
  9428. }
  9429. else
  9430. {
  9431. //DEBUG_INFO("pch=%s\n", pch);
  9432. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9433. protocol, user, password, host, &port, path);
  9434. }
  9435. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9436. {
  9437. DEBUG_INFO("protocol is not ftp/http ! \n");
  9438. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9439. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9440. goto end;
  9441. }
  9442. if(strncmp(locationstr,"http", 4) == 0)
  9443. {
  9444. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9445. sprintf(ftppath,"/%s", path);
  9446. do
  9447. {
  9448. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9449. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9450. sleep(3);
  9451. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9452. if(!isSuccess)
  9453. {
  9454. DEBUG_INFO("Diagnostics fail.\n");
  9455. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9456. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9457. sleep(retryIntervalInt);
  9458. }
  9459. else
  9460. {
  9461. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9462. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9463. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9464. }
  9465. retriesInt--;
  9466. }while((isSuccess == 0)&&(retriesInt >= 0));
  9467. }
  9468. else
  9469. {
  9470. sscanf(host,"%[^/]%s",host1, path1);
  9471. if(strlen(path) > 0)
  9472. sprintf(ftppath,"/%s", path);
  9473. else
  9474. sprintf(ftppath,"/%s", path1);
  9475. int ftppathlen=strlen(ftppath);
  9476. int i=1;
  9477. char filenametemp[50];
  9478. while(i < ftppathlen)
  9479. {
  9480. int len=ftppathlen-i;
  9481. if(ftppath[len]== 47) // '/' ascll code: 47
  9482. {
  9483. DEBUG_INFO("find '/' all right\n");
  9484. break;
  9485. }
  9486. i=i+1;
  9487. }
  9488. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9489. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9490. filenametemp[i+1] = 0;
  9491. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9492. if(port == 0)
  9493. port = 21;
  9494. do
  9495. {
  9496. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9497. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9498. sleep(3);
  9499. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9500. if(!isSuccess)
  9501. {
  9502. DEBUG_INFO("Diagnostics fail.\n");
  9503. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9504. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9505. sleep(retryIntervalInt);
  9506. }
  9507. else
  9508. {
  9509. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9510. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9511. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9512. }
  9513. retriesInt--;
  9514. }while((!isSuccess)&&(retriesInt >= 0));
  9515. }
  9516. end:
  9517. system("rm -f /mnt/*");
  9518. sleep(5);
  9519. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9520. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9521. interLock.isGetDiagnosticGoing = 0;
  9522. pthread_exit(NULL);
  9523. }
  9524. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9525. {
  9526. mtrace();
  9527. int result = FAIL;
  9528. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9529. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9530. {
  9531. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9532. locallistVersion = -1;
  9533. }
  9534. else
  9535. {
  9536. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9537. OCPP_getListVerion();
  9538. }
  9539. //from db.OCPP_getListVerion
  9540. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9541. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9542. sendGetLocalListVersionConfirmation(uuid,"");
  9543. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9544. return result;
  9545. }
  9546. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9547. {
  9548. mtrace();
  9549. int result = FAIL;
  9550. int connectorIdInt=-1;
  9551. int tempIndex = 0;
  9552. int connectorIdIsNULL, chargingProfileIsNULL;
  9553. char comfirmstr[20]={0};
  9554. char cmdBuf[512];
  9555. json_object *RemoteStartTransaction;
  9556. FILE *fp;
  9557. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9558. if(server_pending == TRUE)
  9559. {
  9560. return 0;
  9561. }
  9562. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9563. RemoteStartTransaction = json_tokener_parse(payload);
  9564. if(!is_error(RemoteStartTransaction))
  9565. {
  9566. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9567. {
  9568. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9569. }
  9570. else
  9571. {
  9572. connectorIdIsNULL = TRUE;
  9573. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9574. {
  9575. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9576. {
  9577. connectorIdIsNULL = FALSE;
  9578. connectorIdInt = (gun_index+1);
  9579. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9580. break;
  9581. }
  9582. }
  9583. }
  9584. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9585. {
  9586. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9587. // Required data
  9588. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9589. // Optional data
  9590. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9591. {
  9592. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9593. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9594. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9595. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9596. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9597. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9598. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9599. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9600. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9601. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9602. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9603. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9604. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9605. {
  9606. 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")));
  9607. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9608. 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"));
  9609. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9610. 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"));
  9611. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9612. 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")));
  9613. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9614. {
  9615. 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++)
  9616. {
  9617. 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"));
  9618. 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"));
  9619. 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)
  9620. 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"));
  9621. }
  9622. }
  9623. }
  9624. }
  9625. else
  9626. {
  9627. chargingProfileIsNULL = TRUE;
  9628. }
  9629. }
  9630. }
  9631. else
  9632. {
  9633. connectorIdIsNULL = TRUE;
  9634. }
  9635. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9636. {
  9637. DEBUG_WARN("Connector id is NULL\n.");
  9638. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9639. goto end;
  9640. }
  9641. /*
  9642. enum _SYSTEM_STATUS
  9643. {
  9644. S_BOOTING = 0,
  9645. S_IDLE, = 1
  9646. S_AUTHORIZING, = 2
  9647. S_REASSIGN_CHECK, = 3
  9648. S_REASSIGN, = 4
  9649. S_PRECHARGE, = 5
  9650. S_PREPARING_FOR_EV, = 6
  9651. S_PREPARING_FOR_EVSE, = 7
  9652. S_CHARGING, = 8
  9653. S_TERMINATING, = 9
  9654. S_COMPLETE, = 10
  9655. S_ALARM, = 11
  9656. S_FAULT = 12
  9657. }
  9658. */
  9659. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9660. {
  9661. //check Transaction active
  9662. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9663. {
  9664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9665. {
  9666. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9667. }
  9668. else
  9669. {
  9670. tempIndex = connectorIdInt -1;
  9671. }
  9672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9673. {
  9674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9675. {
  9676. 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))
  9677. {
  9678. //Reserved
  9679. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9680. }
  9681. 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))
  9682. {
  9683. //Reserved
  9684. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9685. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9686. goto end;
  9687. }
  9688. else
  9689. {
  9690. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9691. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9692. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9694. {
  9695. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9697. goto end;
  9698. }
  9699. }//END FOR ELSE
  9700. }
  9701. }// END FOR CHAdeMO_QUANTITY
  9702. }
  9703. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9704. {
  9705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9706. {
  9707. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9708. }
  9709. else
  9710. {
  9711. tempIndex = connectorIdInt -1;
  9712. }
  9713. for (int index = 0; index < CCS_QUANTITY; index++)
  9714. {
  9715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9716. {
  9717. 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))
  9718. {
  9719. //Reserved
  9720. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9721. }
  9722. 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))
  9723. {
  9724. //Reserved
  9725. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9726. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9727. goto end;
  9728. }
  9729. else
  9730. {
  9731. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9732. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9733. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9734. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9735. {
  9736. DEBUG_WARN("CCS connector not allow start\n.");
  9737. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9738. goto end;
  9739. }
  9740. }// END FOR ELSE
  9741. }
  9742. }// END FOR CCS_QUANTITY
  9743. }
  9744. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9745. {
  9746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9747. {
  9748. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9749. }
  9750. else
  9751. {
  9752. tempIndex = connectorIdInt -1;
  9753. }
  9754. for (int index = 0; index < GB_QUANTITY; index++)
  9755. {
  9756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9757. {
  9758. 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))
  9759. {
  9760. //Reserved
  9761. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9762. }
  9763. 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))
  9764. {
  9765. //Reserved
  9766. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9767. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9768. goto end;
  9769. }
  9770. else
  9771. {
  9772. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9773. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9774. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9775. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9776. {
  9777. DEBUG_WARN("GB connector not allow start\n.");
  9778. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9779. goto end;
  9780. }
  9781. }// END FOR ELSE
  9782. }
  9783. } // END FOR GB_QUANTITY
  9784. }
  9785. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9786. {
  9787. tempIndex = connectorIdInt -1;
  9788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9789. {
  9790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9791. {
  9792. 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))
  9793. {
  9794. //Reserved
  9795. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9796. }
  9797. 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))
  9798. {
  9799. //Reserved
  9800. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9801. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9802. goto end;
  9803. }
  9804. else
  9805. {
  9806. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9807. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9808. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9809. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9810. {
  9811. DEBUG_WARN("GB connector not allow start\n.");
  9812. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9813. goto end;
  9814. }
  9815. }// END FOR ELSE
  9816. }
  9817. } // END FOR GB_QUANTITY
  9818. }
  9819. else
  9820. {
  9821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9822. {
  9823. tempIndex = 2;
  9824. }
  9825. else
  9826. {
  9827. tempIndex = connectorIdInt -1;
  9828. }
  9829. for (int index = 0; index < AC_QUANTITY; index++)
  9830. {
  9831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9832. {
  9833. 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))
  9834. {
  9835. //Reserved
  9836. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9837. }
  9838. 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))
  9839. {
  9840. //Reserved
  9841. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9842. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9843. goto end;
  9844. }
  9845. else
  9846. {
  9847. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9848. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9849. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9850. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9851. {
  9852. DEBUG_WARN("AC connector not allow start\n.");
  9853. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9854. goto end;
  9855. }
  9856. }//END FOR ELSE
  9857. }
  9858. }// END FOR AC_QUANTITY
  9859. }
  9860. if(chargingProfileIsNULL == FALSE)
  9861. {
  9862. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9863. {
  9864. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9865. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9866. //memset idTag
  9867. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9868. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9869. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9870. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9871. // Save profile to file
  9872. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9873. system(cmdBuf);
  9874. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9875. fp = fopen(cmdBuf, "w");
  9876. 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));
  9877. fclose(fp);
  9878. }
  9879. else
  9880. {
  9881. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9882. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9883. }
  9884. }
  9885. else
  9886. {
  9887. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9888. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9889. //memset idTag
  9890. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9891. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9892. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9893. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9894. }
  9895. }
  9896. else
  9897. {
  9898. DEBUG_WARN("Connector id over\n.");
  9899. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9900. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9901. }
  9902. end:
  9903. json_object_put(RemoteStartTransaction);
  9904. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9905. {
  9906. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9907. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9908. }
  9909. //OCPP send RemoteStartConfirmation by first.
  9910. sendRemoteStartConfirmation(uuid, comfirmstr);
  9911. return result;
  9912. }
  9913. int handleRemoteStartRequest(char *uuid, char *payload)
  9914. {
  9915. mtrace();
  9916. int result = PASS;
  9917. int connectorIdInt=-1;
  9918. int tempIndex = 0;
  9919. char comfirmstr[20]={0};
  9920. char cmdBuf[512];
  9921. json_object *RemoteStartTransaction;
  9922. FILE *fp;
  9923. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9924. if(server_pending == TRUE)
  9925. {
  9926. result = FAIL;
  9927. }
  9928. RemoteStartTransaction = json_tokener_parse(payload);
  9929. if(!is_error(RemoteStartTransaction))
  9930. {
  9931. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9932. {
  9933. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9934. }
  9935. else
  9936. {
  9937. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9938. {
  9939. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9940. {
  9941. connectorIdInt = (gun_index+1);
  9942. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9943. break;
  9944. }
  9945. }
  9946. }
  9947. if(connectorIdInt == 0)
  9948. {
  9949. DEBUG_WARN("Connector id shall not equal 0.\n");
  9950. result = FAIL;
  9951. }
  9952. else if(connectorIdInt == -1)
  9953. {
  9954. DEBUG_INFO("Connector id does not specific.\n");
  9955. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9956. {
  9957. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  9958. // Required data
  9959. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9960. // Optional data
  9961. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9962. {
  9963. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9964. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9965. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9966. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9967. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9968. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9969. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9970. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9971. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9972. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9973. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9974. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9975. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9976. {
  9977. 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")));
  9978. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9979. 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"));
  9980. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9981. 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"));
  9982. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9983. 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")));
  9984. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9985. {
  9986. 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++)
  9987. {
  9988. 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"));
  9989. 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"));
  9990. 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)
  9991. 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"));
  9992. }
  9993. }
  9994. }
  9995. }
  9996. else
  9997. {
  9998. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  9999. }
  10000. }
  10001. }
  10002. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10003. {
  10004. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10005. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10006. // Required data
  10007. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10008. // Optional data
  10009. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10010. {
  10011. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10012. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10013. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10014. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10015. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10016. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10017. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10018. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10020. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10022. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10024. {
  10025. 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")));
  10026. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10027. 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"));
  10028. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10029. 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"));
  10030. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10031. 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")));
  10032. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10033. {
  10034. 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++)
  10035. {
  10036. 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"));
  10037. 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"));
  10038. 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)
  10039. 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"));
  10040. }
  10041. }
  10042. }
  10043. }
  10044. else
  10045. {
  10046. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10047. }
  10048. }
  10049. else
  10050. {
  10051. DEBUG_WARN("Connector id is over maximun value.\n");
  10052. result = FAIL;
  10053. }
  10054. }
  10055. if(result == PASS)
  10056. {
  10057. if(connectorIdInt > 0)
  10058. {
  10059. //check Transaction active
  10060. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10061. {
  10062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10063. {
  10064. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10065. }
  10066. else
  10067. {
  10068. tempIndex = connectorIdInt -1;
  10069. }
  10070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10071. {
  10072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10073. {
  10074. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10075. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10076. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10077. {
  10078. //Reserved
  10079. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10080. }
  10081. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10082. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10083. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10084. {
  10085. //Reserved
  10086. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10087. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10088. goto end;
  10089. }
  10090. else
  10091. {
  10092. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10093. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10094. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10095. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10096. {
  10097. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10098. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10099. goto end;
  10100. }
  10101. }//END FOR ELSE
  10102. }
  10103. }// END FOR CHAdeMO_QUANTITY
  10104. }
  10105. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10106. {
  10107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10108. {
  10109. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10110. }
  10111. else
  10112. {
  10113. tempIndex = connectorIdInt -1;
  10114. }
  10115. for (int index = 0; index < CCS_QUANTITY; index++)
  10116. {
  10117. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10118. {
  10119. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10120. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10121. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10122. {
  10123. //Reserved
  10124. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10125. }
  10126. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10127. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10128. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10129. {
  10130. //Reserved
  10131. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10132. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10133. goto end;
  10134. }
  10135. else
  10136. {
  10137. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10138. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10139. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10140. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10141. {
  10142. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10143. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10144. goto end;
  10145. }
  10146. }// END FOR ELSE
  10147. }
  10148. }// END FOR CCS_QUANTITY
  10149. }
  10150. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10151. {
  10152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10153. {
  10154. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10155. }
  10156. else
  10157. {
  10158. tempIndex = connectorIdInt -1;
  10159. }
  10160. for (int index = 0; index < GB_QUANTITY; index++)
  10161. {
  10162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10163. {
  10164. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10165. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10166. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10167. {
  10168. //Reserved
  10169. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10170. }
  10171. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10172. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10173. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10174. {
  10175. //Reserved
  10176. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10177. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10178. goto end;
  10179. }
  10180. else
  10181. {
  10182. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10183. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10184. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10185. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10186. {
  10187. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10188. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10189. goto end;
  10190. }
  10191. }// END FOR ELSE
  10192. }
  10193. } // END FOR GB_QUANTITY
  10194. }
  10195. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10196. {
  10197. tempIndex = connectorIdInt -1;
  10198. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10199. {
  10200. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10201. {
  10202. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10203. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10204. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10205. {
  10206. //Reserved
  10207. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10208. }
  10209. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10210. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10211. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10212. {
  10213. //Reserved
  10214. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10216. goto end;
  10217. }
  10218. else
  10219. {
  10220. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10221. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10222. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10223. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10224. {
  10225. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10226. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10227. goto end;
  10228. }
  10229. }// END FOR ELSE
  10230. }
  10231. } // END FOR GB_QUANTITY
  10232. }
  10233. else
  10234. {
  10235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10236. {
  10237. tempIndex = 2;
  10238. }
  10239. else
  10240. {
  10241. tempIndex = connectorIdInt -1;
  10242. }
  10243. for (int index = 0; index < AC_QUANTITY; index++)
  10244. {
  10245. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10246. {
  10247. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10248. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10249. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10250. {
  10251. //Reserved
  10252. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10253. }
  10254. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10255. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10256. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10257. {
  10258. //Reserved
  10259. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10260. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10261. goto end;
  10262. }
  10263. else
  10264. {
  10265. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10266. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10267. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10268. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10269. {
  10270. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10272. goto end;
  10273. }
  10274. }//END FOR ELSE
  10275. }
  10276. }// END FOR AC_QUANTITY
  10277. }
  10278. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10279. {
  10280. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10281. {
  10282. // Save profile to file
  10283. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10284. system(cmdBuf);
  10285. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10286. fp = fopen(cmdBuf, "w");
  10287. 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));
  10288. fclose(fp);
  10289. }
  10290. else
  10291. {
  10292. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10293. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10294. goto end;
  10295. }
  10296. }
  10297. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10299. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10300. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10301. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10303. }
  10304. else
  10305. {
  10306. uint8_t isHasIdleConnector = FALSE;
  10307. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10308. {
  10309. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10310. {
  10311. isHasIdleConnector = TRUE;
  10312. break;
  10313. }
  10314. }
  10315. if(isHasIdleConnector == TRUE)
  10316. {
  10317. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10318. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10319. {
  10320. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10321. {
  10322. // Save profile to file
  10323. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10324. system(cmdBuf);
  10325. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10326. fp = fopen(cmdBuf, "w");
  10327. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10328. fclose(fp);
  10329. refreshStartTimer(&clientTime.RemoteStartWait);
  10330. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10331. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10332. }
  10333. else
  10334. {
  10335. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10337. }
  10338. }
  10339. }
  10340. else
  10341. {
  10342. DEBUG_INFO("There is not any connector is idle.\n");
  10343. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10344. }
  10345. }
  10346. }
  10347. else
  10348. {
  10349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10350. }
  10351. end:
  10352. json_object_put(RemoteStartTransaction);
  10353. sendRemoteStartConfirmation(uuid, comfirmstr);
  10354. return result;
  10355. }
  10356. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10357. {
  10358. mtrace();
  10359. int result = FAIL;
  10360. int match = FALSE;
  10361. int GunNO = 0;
  10362. int tempIndex = 0;
  10363. int transactionIdInt=0;
  10364. int transactionIdIsNULL= TRUE;
  10365. char comfirmstr[20];
  10366. json_object *RemoteStopTransaction;
  10367. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10368. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10369. if(server_pending == TRUE)
  10370. {
  10371. return 0;
  10372. }
  10373. RemoteStopTransaction = json_tokener_parse(payload);
  10374. if(!is_error(RemoteStopTransaction))
  10375. {
  10376. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10377. {
  10378. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10379. transactionIdIsNULL = FALSE;
  10380. }
  10381. }
  10382. json_object_put(RemoteStopTransaction);
  10383. if(transactionIdIsNULL == FALSE)
  10384. {
  10385. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10386. {
  10387. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10388. {
  10389. //check Transaction active
  10390. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10391. {
  10392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10393. {
  10394. tempIndex = ((gun_index==2) ? 1: 0);
  10395. }
  10396. else
  10397. {
  10398. tempIndex = gun_index;
  10399. }
  10400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10401. {
  10402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10403. {
  10404. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10405. {
  10406. match = TRUE;
  10407. GunNO = gun_index;
  10408. }
  10409. }
  10410. }// END FOR CHAdeMO_QUANTITY
  10411. }
  10412. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10413. {
  10414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10415. {
  10416. tempIndex = ((gun_index==2) ? 1: 0);
  10417. }
  10418. else
  10419. {
  10420. tempIndex = gun_index;
  10421. }
  10422. for (int index = 0; index < CCS_QUANTITY; index++)
  10423. {
  10424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10425. {
  10426. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10427. {
  10428. match = TRUE;
  10429. GunNO = gun_index;
  10430. }
  10431. }
  10432. }// END FOR CCS_QUANTITY
  10433. }
  10434. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10435. {
  10436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10437. {
  10438. tempIndex = ((gun_index==2) ? 1: 0);
  10439. }
  10440. else
  10441. {
  10442. tempIndex = gun_index;
  10443. }
  10444. for (int index = 0; index < GB_QUANTITY; index++)
  10445. {
  10446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10447. {
  10448. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10449. {
  10450. match = TRUE;
  10451. GunNO = gun_index;
  10452. }
  10453. }
  10454. }// END FOR GB_QUANTITY
  10455. }
  10456. else if(gunType[gun_index] == GUN_TYPE_DO)
  10457. {
  10458. tempIndex = gun_index;
  10459. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10460. {
  10461. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10462. {
  10463. 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
  10464. {
  10465. match = TRUE;
  10466. GunNO = gun_index;
  10467. }
  10468. }
  10469. }// END FOR GB_QUANTITY
  10470. }
  10471. else
  10472. {
  10473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10474. {
  10475. tempIndex = 2;
  10476. }
  10477. else
  10478. {
  10479. tempIndex = gun_index;
  10480. }
  10481. for (int index = 0; index < AC_QUANTITY; index++)
  10482. {
  10483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10484. {
  10485. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10486. {
  10487. match = TRUE;
  10488. GunNO = gun_index;
  10489. }
  10490. }
  10491. }// END FOR CHAdeMO_QUANTITY
  10492. } // END FOR AC ELSE
  10493. }// CHECK IF ResponseTransactionId == transactionIdInt
  10494. }//END FOR
  10495. if( match == TRUE)
  10496. {
  10497. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10498. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10499. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10500. }
  10501. else
  10502. {
  10503. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10504. }
  10505. }
  10506. else
  10507. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10508. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10509. return result;
  10510. }
  10511. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10512. {
  10513. mtrace();
  10514. int result = FAIL;
  10515. int connectorIdInt=0, reservationIdInt=0;
  10516. int tempIndex = 0;
  10517. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10518. char comfirmstr[20]={0};
  10519. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10520. int c = 0;
  10521. char *loc;
  10522. //char *ptr;
  10523. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10524. strcpy(sstrtemp, stringtrimspace(payload));
  10525. //***(1)connectorId ****/
  10526. c=0;
  10527. loc = strstr(sstrtemp, "connectorId");
  10528. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10529. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10530. {
  10531. sstr[c] = loc[strlen("connectorId")+2+c];
  10532. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10533. c++;
  10534. }
  10535. sstr[c] = '\0';
  10536. connectorIdInt = atoi(sstr);
  10537. //***(2)expiryDate ****/
  10538. loc = strstr(sstrtemp, "expiryDate");
  10539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10540. c = 0;
  10541. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10542. {
  10543. sstr[c] = loc[3+strlen("expiryDate")+c];
  10544. c++;
  10545. }
  10546. sstr[c] = '\0';
  10547. strcpy(expiryDatestr, sstr);
  10548. //***(3)idTag ****/
  10549. loc = strstr(sstrtemp, "idTag");
  10550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10551. c = 0;
  10552. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10553. {
  10554. sstr[c] = loc[3+strlen("idTag")+c];
  10555. c++;
  10556. }
  10557. sstr[c] = '\0';
  10558. strcpy(idTagstr, sstr);
  10559. //***(4)parentIdTag ****/
  10560. loc = strstr(sstrtemp, "parentIdTag");
  10561. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10562. c = 0;
  10563. if(loc == NULL)
  10564. {
  10565. strcpy(parentIdTagstr, "");
  10566. }
  10567. else
  10568. {
  10569. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10570. {
  10571. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10572. c++;
  10573. }
  10574. sstr[c] = '\0';
  10575. strcpy(parentIdTagstr, sstr);
  10576. }
  10577. //***(5)reservationId ****/
  10578. c=0;
  10579. loc = strstr(sstrtemp, "reservationId");
  10580. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10581. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10582. {
  10583. sstr[c] = loc[strlen("reservationId")+2+c];
  10584. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10585. c++;
  10586. }
  10587. sstr[c] = '\0';
  10588. reservationIdInt = atoi(sstr);
  10589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10590. /*
  10591. enum SYSTEM_STATUS
  10592. {
  10593. SYS_MODE_BOOTING = 0,
  10594. SYS_MODE_IDLE = 1,
  10595. SYS_MODE_AUTHORIZING = 2,
  10596. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10597. SYS_MODE_REASSIGN = 4,
  10598. SYS_MODE_PREPARING = 5,
  10599. SYS_MODE_PREPARE_FOR_EV = 6,
  10600. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10601. SYS_MODE_CHARGING = 8,
  10602. SYS_MODE_TERMINATING = 9,
  10603. SYS_MODE_COMPLETE = 10,
  10604. SYS_MODE_ALARM = 11,
  10605. SYS_MODE_FAULT = 12,
  10606. SYS_MODE_RESERVATION = 13,
  10607. SYS_MODE_BOOKING = 14,
  10608. SYS_MODE_MAINTAIN = 15,
  10609. SYS_MODE_DEBUG = 16,
  10610. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10611. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10612. SYS_MODE_UPDATE = 19
  10613. };
  10614. */
  10615. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10616. {
  10617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10618. goto end;
  10619. }
  10620. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10621. {
  10622. //check Transaction active
  10623. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10624. {
  10625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10626. {
  10627. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10628. }
  10629. else
  10630. {
  10631. tempIndex = connectorIdInt -1;
  10632. }
  10633. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10634. {
  10635. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10636. {
  10637. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10638. {
  10639. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10640. {
  10641. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10642. {
  10643. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10645. }
  10646. 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'))
  10647. {
  10648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10649. }
  10650. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10651. {
  10652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10653. }
  10654. else
  10655. {
  10656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10657. }
  10658. }
  10659. 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
  10660. {
  10661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10662. }
  10663. }
  10664. else
  10665. {
  10666. //replace reservation
  10667. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10669. }
  10670. }
  10671. } // END FOR CHAdeMO_QUANTITY
  10672. }
  10673. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10674. {
  10675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10676. {
  10677. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10678. }
  10679. else
  10680. {
  10681. tempIndex = connectorIdInt -1;
  10682. }
  10683. for (int index = 0; index < CCS_QUANTITY; index++)
  10684. {
  10685. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10686. {
  10687. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10688. {
  10689. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10690. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10691. {
  10692. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10693. {
  10694. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10696. }
  10697. 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'))
  10698. {
  10699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10700. }
  10701. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10702. {
  10703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10704. }
  10705. else
  10706. {
  10707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10708. }
  10709. }
  10710. 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
  10711. {
  10712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10713. }
  10714. }
  10715. else
  10716. {
  10717. //replace reservation
  10718. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10720. }
  10721. }
  10722. } // END FOR CCS_QUANTITY
  10723. }
  10724. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10725. {
  10726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10727. {
  10728. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10729. }
  10730. else
  10731. {
  10732. tempIndex = connectorIdInt -1;
  10733. }
  10734. for (int index = 0; index < GB_QUANTITY; index++)
  10735. {
  10736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10737. {
  10738. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10739. {
  10740. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10741. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10742. {
  10743. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10744. {
  10745. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10747. }
  10748. 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'))
  10749. {
  10750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10751. }
  10752. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10753. {
  10754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10755. }
  10756. else
  10757. {
  10758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10759. }
  10760. }
  10761. 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
  10762. {
  10763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10764. }
  10765. }
  10766. else
  10767. {
  10768. //replace reservation
  10769. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10771. }
  10772. }
  10773. }// END FOR GB_QUANTITY
  10774. }
  10775. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10776. {
  10777. tempIndex = connectorIdInt -1;
  10778. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10779. {
  10780. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10781. {
  10782. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10783. {
  10784. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10785. 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
  10786. {
  10787. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10788. {
  10789. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10791. }
  10792. 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'))
  10793. {
  10794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10795. }
  10796. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10797. {
  10798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10799. }
  10800. else
  10801. {
  10802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10803. }
  10804. }
  10805. 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
  10806. {
  10807. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10808. }
  10809. }
  10810. else
  10811. {
  10812. //replace reservation
  10813. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10815. }
  10816. }
  10817. }// END FOR GB_QUANTITY
  10818. }
  10819. else
  10820. {
  10821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10822. {
  10823. tempIndex = 2;
  10824. }
  10825. else
  10826. {
  10827. tempIndex = (connectorIdInt -1);
  10828. }
  10829. for (int index = 0; index < AC_QUANTITY; index++)
  10830. {
  10831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10832. {
  10833. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10834. {
  10835. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10836. {
  10837. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10838. {
  10839. 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))
  10840. {
  10841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10842. }
  10843. else
  10844. {
  10845. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10847. }
  10848. }
  10849. 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'))
  10850. {
  10851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10852. }
  10853. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10854. {
  10855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10856. }
  10857. else
  10858. {
  10859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10860. }
  10861. }
  10862. 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
  10863. {
  10864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10865. }
  10866. }
  10867. else
  10868. {
  10869. //replace reservation
  10870. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10872. }
  10873. }
  10874. } // END FOR AC_QUANTITY
  10875. }
  10876. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10877. }
  10878. else if(connectorIdInt == 0)
  10879. {
  10880. //check Transaction active
  10881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10882. {
  10883. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10884. {
  10885. 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'))
  10886. {
  10887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10888. goto end;
  10889. }
  10890. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10891. {
  10892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10893. goto end;
  10894. }
  10895. 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
  10896. {
  10897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10898. goto end;
  10899. }
  10900. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10901. {
  10902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10903. goto end;
  10904. }
  10905. }
  10906. }// END FOR CHAdeMO_QUANTITY
  10907. for (int index = 0; index < CCS_QUANTITY; index++)
  10908. {
  10909. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10910. {
  10911. 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'))
  10912. {
  10913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10914. goto end;
  10915. }
  10916. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10917. {
  10918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10919. goto end;
  10920. }
  10921. 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
  10922. {
  10923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10924. goto end;
  10925. }
  10926. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10927. {
  10928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10929. goto end;
  10930. }
  10931. }
  10932. } // END FOR CCS_QUANTITY
  10933. for (int index = 0; index < GB_QUANTITY; index++)
  10934. {
  10935. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10936. {
  10937. 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'))
  10938. {
  10939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10940. goto end;
  10941. }
  10942. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10943. {
  10944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10945. goto end;
  10946. }
  10947. 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
  10948. {
  10949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10950. goto end;
  10951. }
  10952. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10953. {
  10954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10955. goto end;
  10956. }
  10957. }
  10958. } // END FOR GB_QUANTITY
  10959. for (int index = 0; index < AC_QUANTITY; index++)
  10960. {
  10961. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10962. {
  10963. 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'))
  10964. {
  10965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10966. goto end;
  10967. }
  10968. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10969. {
  10970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10971. goto end;
  10972. }
  10973. 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
  10974. {
  10975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10976. goto end;
  10977. }
  10978. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10979. {
  10980. 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))
  10981. {
  10982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10983. goto end;
  10984. }
  10985. }
  10986. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10987. {
  10988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10989. goto end;
  10990. }
  10991. }
  10992. }// END FOR AC_QUANTITY
  10993. //The connectorId is 0
  10994. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10996. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10997. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10998. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10999. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11000. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11001. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11002. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11003. result = TRUE;
  11004. return result;
  11005. }
  11006. else
  11007. {
  11008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11009. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11010. }
  11011. if(strcmp(comfirmstr,"Accepted") == 0)
  11012. {
  11013. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11014. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11015. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11016. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11017. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11018. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11019. result = TRUE;
  11020. return result;
  11021. }
  11022. end:
  11023. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11024. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11025. return result;
  11026. }
  11027. int handleResetRequest(char *uuid, char *payload)
  11028. {
  11029. mtrace();
  11030. int result = FAIL;
  11031. char sstr[10]={0},sstrtemp[30]={ 0 };
  11032. char typestr[10]={0};
  11033. char comfirmstr[20]={0};
  11034. int c = 0;
  11035. char *loc;
  11036. DEBUG_INFO("handleResetRequest...\n");
  11037. strcpy(sstrtemp, stringtrimspace(payload));
  11038. loc = strstr(sstrtemp, "type");
  11039. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11040. c = 0;
  11041. while (loc[3+strlen("type")+c] != '\"')
  11042. {
  11043. sstr[c] = loc[3+strlen("type")+c];
  11044. c++;
  11045. }
  11046. sstr[c] = '\0';
  11047. strcpy(typestr,sstr);
  11048. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11049. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11050. {
  11051. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11052. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11053. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11054. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11055. }
  11056. else
  11057. {
  11058. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11059. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11060. result = PASS;
  11061. }
  11062. sendResetConfirmation(uuid, comfirmstr);
  11063. return result;
  11064. }
  11065. int handleSendLocalListRequest(char *uuid, char *payload)
  11066. {
  11067. mtrace();
  11068. int result = FAIL;
  11069. char comfirmstr[20];
  11070. int checkState_Faulted = FALSE;
  11071. json_object *SendLocalList;
  11072. DEBUG_INFO("handleSendLocalListRequest...\n");
  11073. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11074. {
  11075. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11076. goto end;
  11077. }
  11078. //check Charge Point state
  11079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11080. {
  11081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11082. {
  11083. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11084. }
  11085. }
  11086. for (int index = 0; index < CCS_QUANTITY; index++)
  11087. {
  11088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11089. {
  11090. checkState_Faulted = TRUE; //OCPP Status
  11091. }
  11092. }
  11093. for (int index = 0; index < GB_QUANTITY; index++)
  11094. {
  11095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11096. {
  11097. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11098. }
  11099. }
  11100. //check Charge Point state
  11101. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11102. {
  11103. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11104. {
  11105. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11106. }
  11107. }
  11108. //check Charge Point state
  11109. for (int index = 0; index < AC_QUANTITY; index++)
  11110. {
  11111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11112. {
  11113. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11114. }
  11115. }
  11116. if(checkState_Faulted == TRUE)
  11117. {
  11118. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11119. goto end;
  11120. }
  11121. // Parsing payload
  11122. SendLocalList = json_tokener_parse(payload);
  11123. if(!is_error(SendLocalList))
  11124. {
  11125. // Required data
  11126. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11127. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11128. // Optional data
  11129. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11130. {
  11131. //Check UpdateType
  11132. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11133. {
  11134. //Local list full update
  11135. DEBUG_INFO("Local list full update.\n");
  11136. OCPP_getListVerion();
  11137. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11138. {
  11139. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11140. goto end;
  11141. }
  11142. OCPP_cleanLocalList();
  11143. }
  11144. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11145. {
  11146. //Local list different update
  11147. DEBUG_INFO("Local list different update.\n");
  11148. OCPP_getListVerion();
  11149. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11150. {
  11151. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11152. goto end;
  11153. }
  11154. }
  11155. else
  11156. {
  11157. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11158. goto end;
  11159. }
  11160. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11161. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11162. {
  11163. 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")));
  11164. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11165. {
  11166. 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")));
  11167. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11168. 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")));
  11169. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11170. 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")));
  11171. }
  11172. // Add to db
  11173. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11174. {
  11175. //Local list full update
  11176. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11177. idx,
  11178. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11179. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11180. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11181. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11182. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11183. // update list
  11184. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11185. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11186. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11187. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11188. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11189. }
  11190. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11191. {
  11192. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11193. idx,
  11194. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11195. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11196. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11197. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11198. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11199. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11200. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11201. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11202. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11203. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11204. }
  11205. }
  11206. }
  11207. else
  11208. {
  11209. //Check UpdateType
  11210. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11211. {
  11212. //Local list full update
  11213. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11214. OCPP_cleanLocalList();
  11215. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11216. goto end;
  11217. }
  11218. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11219. {
  11220. //Local list different update
  11221. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11222. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11223. goto end;
  11224. }
  11225. }
  11226. result = PASS;
  11227. }
  11228. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11229. end:
  11230. json_object_put(SendLocalList);
  11231. sendSendLocalListConfirmation(uuid, comfirmstr);
  11232. return result;
  11233. }
  11234. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11235. {
  11236. mtrace();
  11237. int result = FAIL;
  11238. struct StructSetChargingProfile SetProfileReq = {0};
  11239. int tempchargingProfileIdInt;
  11240. int chargingSchedulePeriodCount = 0;
  11241. char comfirmstr[20]={0};
  11242. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11243. char rmFileCmd[128]={0};
  11244. int profileQuantity = 0;
  11245. json_object *SetChargingProfile;
  11246. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11247. SetChargingProfile = json_tokener_parse(payload);
  11248. if(!is_error(SetChargingProfile))
  11249. {
  11250. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11251. {
  11252. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11253. }
  11254. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11255. {
  11256. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11257. {
  11258. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11259. }
  11260. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11261. {
  11262. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11263. }
  11264. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11265. {
  11266. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11267. }
  11268. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11269. {
  11270. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11271. }
  11272. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11273. {
  11274. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11275. }
  11276. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11277. {
  11278. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11279. }
  11280. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11281. {
  11282. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11283. }
  11284. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11285. {
  11286. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11287. }
  11288. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11289. {
  11290. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11291. {
  11292. 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")));
  11293. }
  11294. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11295. {
  11296. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11297. }
  11298. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11299. {
  11300. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11301. }
  11302. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11303. {
  11304. 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")));
  11305. }
  11306. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11307. {
  11308. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11309. if(chargingSchedulePeriodCount <= 10)
  11310. {
  11311. 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++)
  11312. {
  11313. 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)
  11314. {
  11315. 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"));
  11316. }
  11317. 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)
  11318. {
  11319. 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"));
  11320. }
  11321. 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)
  11322. {
  11323. 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"));
  11324. }
  11325. }
  11326. }
  11327. }
  11328. }
  11329. }
  11330. }
  11331. // Profile periods quantity check
  11332. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11333. {
  11334. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11335. goto end;
  11336. }
  11337. // Check invalid limit
  11338. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11339. {
  11340. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11341. {
  11342. 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)))) ||
  11343. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11344. {
  11345. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11346. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11347. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11348. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11349. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11350. goto end;
  11351. }
  11352. }
  11353. }
  11354. else
  11355. {
  11356. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11357. {
  11358. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:modelnameInfo.ParsingInfo[0].Current)))
  11359. {
  11360. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11361. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11362. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11363. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11364. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11365. goto end;
  11366. }
  11367. }
  11368. }
  11369. // Profile purpose info check
  11370. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11371. {
  11372. FILE *fp;
  11373. char dataLine[4096]={0};
  11374. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11375. if(SetProfileReq.ConnectorId != 0)
  11376. {
  11377. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11378. goto end;
  11379. }
  11380. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11381. if (!fp)
  11382. {
  11383. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11384. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11385. }
  11386. else
  11387. {
  11388. while(fscanf(fp, "%s", dataLine) != EOF)
  11389. {
  11390. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11391. {
  11392. profileQuantity += 1;
  11393. }
  11394. }
  11395. }
  11396. fclose(fp);
  11397. }
  11398. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11399. {
  11400. FILE *fp;
  11401. char dataLine[4096]={0};
  11402. char filename[128]={0};
  11403. int tmpProfileQuantity;
  11404. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11405. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11406. {
  11407. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11408. goto end;
  11409. }
  11410. if(SetProfileReq.ConnectorId == 0)
  11411. {
  11412. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11413. {
  11414. tmpProfileQuantity = 0;
  11415. memset(filename, 0, ARRAY_SIZE(filename));
  11416. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11417. fp = fopen(filename, "r");
  11418. if (!fp)
  11419. {
  11420. DEBUG_INFO("%s does not create.\n", filename);
  11421. fp = fopen(filename, "w+");
  11422. }
  11423. else
  11424. {
  11425. while(fscanf(fp, "%s", dataLine) != EOF)
  11426. {
  11427. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11428. {
  11429. tmpProfileQuantity += 1;
  11430. }
  11431. }
  11432. }
  11433. fclose(fp);
  11434. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11435. }
  11436. }
  11437. else
  11438. {
  11439. memset(filename, 0, ARRAY_SIZE(filename));
  11440. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11441. fp = fopen(filename, "r");
  11442. if (!fp)
  11443. {
  11444. DEBUG_INFO("%s does not create.\n", filename);
  11445. fp = fopen(filename, "w+");
  11446. }
  11447. else
  11448. {
  11449. while(fscanf(fp, "%s", dataLine) != EOF)
  11450. {
  11451. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11452. {
  11453. profileQuantity += 1;
  11454. }
  11455. }
  11456. }
  11457. fclose(fp);
  11458. }
  11459. }
  11460. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11461. {
  11462. int isMatchTransactiodId= FALSE;
  11463. FILE *fp;
  11464. char dataLine[4096]={0};
  11465. char filename[128]={0};
  11466. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11467. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11468. if(SetProfileReq.ConnectorId == 0)
  11469. {
  11470. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11471. goto end;
  11472. }
  11473. int tempIndex = 0;
  11474. //check Transaction active
  11475. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11476. {
  11477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11478. {
  11479. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11480. }
  11481. else
  11482. {
  11483. tempIndex = SetProfileReq.ConnectorId -1;
  11484. }
  11485. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11486. {
  11487. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11488. {
  11489. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11490. {
  11491. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11492. {
  11493. isMatchTransactiodId = TRUE;
  11494. break;
  11495. }
  11496. }
  11497. }
  11498. }
  11499. }
  11500. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11501. {
  11502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11503. {
  11504. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11505. }
  11506. else
  11507. {
  11508. tempIndex = SetProfileReq.ConnectorId -1;
  11509. }
  11510. for (int index = 0; index < CCS_QUANTITY; index++)
  11511. {
  11512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11513. {
  11514. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11515. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11516. {
  11517. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11518. {
  11519. isMatchTransactiodId = TRUE;
  11520. break;
  11521. }
  11522. }
  11523. }
  11524. }
  11525. }
  11526. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11527. {
  11528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11529. {
  11530. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11531. }
  11532. else
  11533. {
  11534. tempIndex = SetProfileReq.ConnectorId -1;
  11535. }
  11536. for (int index = 0; index < GB_QUANTITY; index++)
  11537. {
  11538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11539. {
  11540. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11541. {
  11542. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11543. {
  11544. isMatchTransactiodId = TRUE;
  11545. break;
  11546. }
  11547. }
  11548. }
  11549. }
  11550. }
  11551. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11552. {
  11553. tempIndex = SetProfileReq.ConnectorId -1;
  11554. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11555. {
  11556. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11557. {
  11558. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11559. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11560. {
  11561. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11562. {
  11563. isMatchTransactiodId = TRUE;
  11564. break;
  11565. }
  11566. }
  11567. }
  11568. }
  11569. }
  11570. else
  11571. {
  11572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11573. {
  11574. tempIndex = 2;
  11575. }
  11576. else
  11577. {
  11578. tempIndex = (SetProfileReq.ConnectorId -1);
  11579. }
  11580. for (int index = 0; index < AC_QUANTITY; index++)
  11581. {
  11582. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11583. {
  11584. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11585. {
  11586. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11587. {
  11588. isMatchTransactiodId = TRUE;
  11589. break;
  11590. }
  11591. }
  11592. }
  11593. }
  11594. }
  11595. //check Transaction active
  11596. if(isMatchTransactiodId == FALSE)
  11597. {
  11598. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11599. goto end;
  11600. }
  11601. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11602. {
  11603. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11604. goto end;
  11605. }
  11606. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11607. fp = fopen(filename, "r");
  11608. if (!fp)
  11609. {
  11610. DEBUG_INFO("%s does not create.\n", filename);
  11611. fp = fopen(filename, "w+");
  11612. }
  11613. else
  11614. {
  11615. //Check Charging Profile Count
  11616. while(fscanf(fp, "%s", dataLine) != EOF)
  11617. {
  11618. //DEBUG_INFO("word=%s\n",word);
  11619. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11620. {
  11621. profileQuantity += 1;
  11622. }
  11623. }
  11624. }
  11625. fclose(fp);
  11626. }
  11627. // Check ChargeProfileMaxStackLevel
  11628. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11629. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11630. {
  11631. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11632. goto end;
  11633. }
  11634. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11635. {
  11636. FILE *fp;
  11637. char dataLine[4096]={0};
  11638. char fnametemp[128]={0};
  11639. int tmpProfileQuantity;
  11640. //Check ChargePointMaxProfile.json exit
  11641. profileQuantity = 0;
  11642. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11643. {
  11644. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11645. //Check Charging Profile Count
  11646. tmpProfileQuantity = 0;
  11647. while(fscanf(fp, "%s", dataLine) != EOF)
  11648. {
  11649. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11650. {
  11651. profileQuantity += 1;
  11652. tmpProfileQuantity += 1;
  11653. }
  11654. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11655. }
  11656. fclose(fp);
  11657. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11658. }
  11659. //Check TxDefaultProfile_%d.json
  11660. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11661. {
  11662. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11663. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11664. if((access(fnametemp,F_OK))!=-1)
  11665. {
  11666. fp = fopen(fnametemp, "r");
  11667. //Check Charging Profile Count
  11668. tmpProfileQuantity = 0;
  11669. while(fscanf(fp, "%s", dataLine) != EOF)
  11670. {
  11671. //DEBUG_INFO("word=%s\n",word);
  11672. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11673. {
  11674. profileQuantity += 1;
  11675. tmpProfileQuantity += 1;
  11676. }
  11677. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11678. }
  11679. fclose(fp);
  11680. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11681. }
  11682. }
  11683. //Check TxProfile_%d.json
  11684. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11685. {
  11686. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11687. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11688. if((access(fnametemp,F_OK))!=-1)
  11689. {
  11690. fp = fopen(fnametemp, "r");
  11691. //Check Charging Profile Count
  11692. tmpProfileQuantity = 0;
  11693. while(fscanf(fp, "%s", dataLine) != EOF)
  11694. {
  11695. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11696. {
  11697. profileQuantity += 1;
  11698. tmpProfileQuantity += 1;
  11699. }
  11700. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11701. }
  11702. fclose(fp);
  11703. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11704. }
  11705. }
  11706. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11707. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11708. {
  11709. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11710. goto end;
  11711. }
  11712. }
  11713. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11714. //**********************************Write to File********************************************************/
  11715. {
  11716. FILE *infile;
  11717. FILE *outfile;
  11718. char dataLine[4096]={0};
  11719. char filename[128]={0};
  11720. int chkChar=0;
  11721. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11722. {
  11723. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11724. {
  11725. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11726. }
  11727. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11728. {
  11729. if(SetProfileReq.ConnectorId==0)
  11730. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11731. else
  11732. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11733. }
  11734. else
  11735. {
  11736. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11737. }
  11738. infile = fopen (filename, "r");
  11739. outfile = fopen (tempfile, "w");
  11740. chkChar = fgetc(infile);
  11741. rewind(infile);
  11742. if(chkChar == EOF)
  11743. {
  11744. // Profile is empty
  11745. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11746. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11747. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11748. fclose(infile);
  11749. fclose(outfile);
  11750. sprintf(rmFileCmd,"rm -f %s",filename);
  11751. system(rmFileCmd);
  11752. rename(tempfile, filename);
  11753. }
  11754. else
  11755. {
  11756. // Profile is not empty
  11757. int ChargingProfileAdded = FALSE;
  11758. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11759. {
  11760. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11761. json_object *tmpChargingProfile;
  11762. tmpChargingProfile = json_tokener_parse(dataLine);
  11763. if(!is_error(SetChargingProfile))
  11764. {
  11765. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11766. {
  11767. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11768. {
  11769. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11770. }
  11771. }
  11772. }
  11773. json_object_put(tmpChargingProfile);
  11774. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11775. {
  11776. if(ChargingProfileAdded == FALSE)
  11777. {
  11778. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11779. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11780. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11781. ChargingProfileAdded = TRUE;
  11782. }
  11783. }
  11784. else
  11785. {
  11786. fprintf(outfile,"%s\n",dataLine);
  11787. if(ChargingProfileAdded == FALSE)
  11788. {
  11789. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11790. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11791. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11792. ChargingProfileAdded = TRUE;
  11793. }
  11794. }
  11795. } // end of while loop
  11796. fclose(infile);
  11797. fclose(outfile);
  11798. sprintf(rmFileCmd,"rm -f %s",filename);
  11799. system(rmFileCmd);
  11800. rename(tempfile, filename);
  11801. }
  11802. }
  11803. sleep(1);
  11804. result = TRUE;
  11805. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11806. }
  11807. end:
  11808. json_object_put(SetChargingProfile);
  11809. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11810. {
  11811. if(SetProfileReq.ConnectorId == 0)
  11812. {
  11813. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11814. {
  11815. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11816. }
  11817. }
  11818. else
  11819. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11820. }
  11821. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11822. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11823. return result;
  11824. }
  11825. int handleTriggerMessageRequest(char *uuid, char *payload)
  11826. {
  11827. mtrace();
  11828. int result = FAIL;
  11829. int connectorIdIsNULL = FALSE;
  11830. int connectorIdInt =0;
  11831. char sstr[40]={0},sstrtemp[100]={ 0 };
  11832. char requestedMessagestr[40]={0};
  11833. char comfirmstr[20]={0};
  11834. int c = 0;
  11835. char *loc;
  11836. DEBUG_INFO("handleTriggerMessageRequest\n");
  11837. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11838. strcpy(sstrtemp, stringtrimspace(payload));
  11839. c = 0;
  11840. loc = strstr(sstrtemp, "requestedMessage");
  11841. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11842. {
  11843. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11844. c++;
  11845. }
  11846. sstr[c] = '\0';
  11847. strcpy(requestedMessagestr, sstr);
  11848. c = 0;
  11849. loc = strstr(sstrtemp, "connectorId");
  11850. if(loc == NULL)
  11851. {
  11852. connectorIdIsNULL = TRUE;
  11853. }
  11854. else
  11855. {
  11856. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11857. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11858. {
  11859. sstr[c] = loc[strlen("connectorId")+2+c];
  11860. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11861. c++;
  11862. }
  11863. sstr[c] = '\0';
  11864. connectorIdInt = atoi(sstr);
  11865. }
  11866. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11867. {
  11868. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11869. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11870. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11871. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11872. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11873. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11874. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11875. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11876. {
  11877. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11878. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11879. return TRUE;
  11880. }
  11881. else
  11882. {
  11883. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11884. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11885. }
  11886. }
  11887. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11888. {
  11889. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11890. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11891. return TRUE;
  11892. }
  11893. //==========================
  11894. // Trigger message
  11895. //==========================
  11896. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11897. {
  11898. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11899. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11900. {
  11901. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11902. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11903. }
  11904. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11905. }
  11906. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11907. {
  11908. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11909. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11910. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11911. }
  11912. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11913. {
  11914. //sendBootNotificationRequest();
  11915. server_sign = FALSE;
  11916. }
  11917. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11918. {
  11919. refreshStartTimer(&clientTime.Heartbeat);
  11920. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  11921. }
  11922. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11923. {
  11924. if(connectorIdIsNULL == FALSE)
  11925. {
  11926. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11927. {
  11928. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11929. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11930. }
  11931. }
  11932. else
  11933. {
  11934. for(int idx=0;idx< gunTotalNumber;idx++)
  11935. {
  11936. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11937. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11938. }
  11939. }
  11940. }
  11941. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11942. {
  11943. if(connectorIdIsNULL == FALSE)
  11944. {
  11945. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11946. {
  11947. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11948. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11949. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11950. }
  11951. }
  11952. else
  11953. {
  11954. for(int idx=0;idx< gunTotalNumber;idx++)
  11955. {
  11956. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11957. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11958. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11959. }
  11960. }
  11961. }
  11962. return result;
  11963. }
  11964. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11965. {
  11966. mtrace();
  11967. int result = FAIL;
  11968. int connectorIdInt =0;
  11969. char comfirmstr[20]={0};
  11970. int tempIndex = 0;
  11971. json_object *UnlockConnector;
  11972. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11973. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11974. UnlockConnector = json_tokener_parse(payload);
  11975. if(!is_error(UnlockConnector))
  11976. {
  11977. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11978. {
  11979. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11980. }
  11981. }
  11982. json_object_put(UnlockConnector);
  11983. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11984. if(gunTotalNumber == 0)
  11985. {
  11986. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11987. goto end;
  11988. }
  11989. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11990. {
  11991. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11992. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11993. goto end;
  11994. }
  11995. else
  11996. {
  11997. //check Transaction active
  11998. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11999. {
  12000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12001. {
  12002. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12003. }
  12004. else
  12005. {
  12006. tempIndex = connectorIdInt -1;
  12007. }
  12008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12009. {
  12010. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12011. {
  12012. //stop Transaction
  12013. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12014. }
  12015. }
  12016. }
  12017. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12018. {
  12019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12020. {
  12021. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12022. }
  12023. else
  12024. {
  12025. tempIndex = connectorIdInt -1;
  12026. }
  12027. for (int index = 0; index < CCS_QUANTITY; index++)
  12028. {
  12029. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12030. {
  12031. //stop Transaction
  12032. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12033. }
  12034. }
  12035. }
  12036. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12037. {
  12038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12039. {
  12040. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12041. }
  12042. else
  12043. {
  12044. tempIndex = connectorIdInt -1;
  12045. }
  12046. for (int index = 0; index < GB_QUANTITY; index++)
  12047. {
  12048. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12049. {
  12050. //stop Transaction
  12051. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12052. }
  12053. }
  12054. }
  12055. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12056. {
  12057. tempIndex = connectorIdInt -1;
  12058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12059. {
  12060. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12061. {
  12062. //stop Transaction
  12063. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12064. }
  12065. }
  12066. }
  12067. else
  12068. {
  12069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12070. {
  12071. tempIndex = 2;
  12072. }
  12073. else
  12074. {
  12075. tempIndex = connectorIdInt-1;
  12076. }
  12077. for (int index = 0; index < AC_QUANTITY; index++)
  12078. {
  12079. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12080. {
  12081. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12082. }
  12083. }
  12084. }
  12085. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12086. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12087. result = TRUE;
  12088. return result;
  12089. }
  12090. end:
  12091. //json_object_put(obj); --- remove temporally
  12092. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12093. return result;
  12094. }
  12095. static char UpdateFirmwarepayloadData[300]={0};
  12096. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12097. {
  12098. mtrace();
  12099. int result = FAIL;
  12100. pthread_t t;
  12101. sendUpdateFirmwareConfirmation(uuid);
  12102. memset(UpdateFirmwarepayloadData, 0, 300);
  12103. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12104. if(!interLock.isUpdateFirmwareGoing)
  12105. {
  12106. interLock.isUpdateFirmwareGoing = 1;
  12107. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12108. sleep(1);
  12109. }
  12110. else
  12111. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12112. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12113. return result;
  12114. }
  12115. void *UpdateFirmwareProcess(void *data)
  12116. {
  12117. pthread_detach(pthread_self());
  12118. mtrace();
  12119. int retriesInt =0, retryIntervalInt=0;
  12120. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12121. int port=0;
  12122. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12123. int isSuccess = 0;
  12124. char ftpbuf[512];
  12125. char temp[100];
  12126. char * pch;
  12127. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12128. json_object *UpdateFirmware;
  12129. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12130. if(!is_error(UpdateFirmware))
  12131. {
  12132. // Required data
  12133. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12134. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12135. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12136. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12137. // Optional data
  12138. if(json_object_object_get(UpdateFirmware, "retries"))
  12139. {
  12140. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12141. }
  12142. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12143. {
  12144. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12145. }
  12146. }
  12147. json_object_put(UpdateFirmware);
  12148. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12149. memset(path, 0, ARRAY_SIZE(path));
  12150. // Wait retrieveData
  12151. if(strlen(retrieveDatestr) > 10)
  12152. {
  12153. do
  12154. {
  12155. sleep(1);
  12156. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12157. }
  12158. // Ready to download
  12159. system("rm -f /mnt/*");
  12160. if(strncmp(locationstr,"http", 4) == 0)
  12161. {
  12162. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12163. sprintf(ftppath,"/%s", path);
  12164. DEBUG_INFO("locationstr: %s\n", locationstr);
  12165. DEBUG_INFO("protocol: %s\n",protocol);
  12166. DEBUG_INFO("host: %s\n",host);
  12167. DEBUG_INFO("path: %s\n",path);
  12168. DEBUG_INFO("ftppath: %s\n",ftppath);
  12169. int ftppathlen=strlen(ftppath);
  12170. int i=1;
  12171. char filenametemp[50];
  12172. while(i < ftppathlen)
  12173. {
  12174. int len=ftppathlen-i;
  12175. if(ftppath[len]== 47) // '/' ascll code: 47
  12176. {
  12177. DEBUG_INFO("compare '/' all right\n");
  12178. break;
  12179. }
  12180. i=i+1;
  12181. }
  12182. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12183. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12184. filenametemp[i+1] = 0;
  12185. do
  12186. {
  12187. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12188. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12189. sleep(1);
  12190. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12191. if(!isSuccess)
  12192. {
  12193. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12194. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12195. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12196. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12197. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12198. }
  12199. else
  12200. {
  12201. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12202. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12203. }
  12204. retriesInt--;
  12205. }while((isSuccess == 0)&&(retriesInt >= 0));
  12206. }
  12207. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12208. {
  12209. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12210. memset(temp, 0, ARRAY_SIZE(temp));
  12211. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12212. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12213. int ftppathlen=strlen(ftpbuf);
  12214. int i=1;
  12215. char filenametemp[50];
  12216. while(i < ftppathlen)
  12217. {
  12218. int len=ftppathlen-i;
  12219. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12220. {
  12221. DEBUG_INFO(" compare '/' all right\n");
  12222. break;
  12223. }
  12224. i=i+1;
  12225. }
  12226. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12227. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12228. filenametemp[i+1] = 0;
  12229. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12230. pch=strchr(temp,'@');
  12231. if(pch==NULL)
  12232. {
  12233. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12234. protocol, host, &port, path);
  12235. strcpy(user,"anonymous");
  12236. strcpy(password,"");
  12237. }
  12238. else
  12239. {
  12240. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12241. protocol, user, password, host, &port, path);
  12242. }
  12243. sscanf(host,"%[^/]%s",host1, path1);
  12244. sprintf(ftppath,"%s", path1);
  12245. //DEBUG_INFO("protocol =%s\n",protocol);
  12246. //DEBUG_INFO("user =%s\n",user);
  12247. //DEBUG_INFO("password =%s\n",password);
  12248. //DEBUG_INFO("host1 =%s\n",host1);
  12249. //DEBUG_INFO("port =%d\n",port);
  12250. //DEBUG_INFO("path1 =%s\n",path1);
  12251. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12252. //ftpFile(host, user, password, port, ftppath, fname);
  12253. //download firmware pthred
  12254. if(port == 0)
  12255. {
  12256. port = 21;
  12257. }
  12258. do
  12259. {
  12260. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12261. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12262. sleep(1);
  12263. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12264. if(!isSuccess)
  12265. {
  12266. //BulldogUtil.sleepMs(interval*1000);
  12267. DEBUG_INFO("Update firmware request and download file fail.\n");
  12268. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12269. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12270. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12271. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12272. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12273. }
  12274. else
  12275. {
  12276. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12277. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12278. }
  12279. retriesInt--;
  12280. }while((!isSuccess)&&(retriesInt >= 0));
  12281. }
  12282. else
  12283. {
  12284. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12285. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12286. sleep(1);
  12287. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12288. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12289. }
  12290. // OCPPPH only, must announce CSU upgrade firmware
  12291. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12292. interLock.isUpdateFirmwareGoing = 0;
  12293. pthread_exit(NULL);
  12294. }
  12295. int handleCertificateSignedRequest(char *uuid, char *payload)
  12296. {
  12297. mtrace();
  12298. int result = PASS;
  12299. json_object *CertificateSigned;
  12300. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12301. CertificateSigned = json_tokener_parse(payload);
  12302. if(!is_error(CertificateSigned))
  12303. {
  12304. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12305. }
  12306. json_object_put(CertificateSigned);
  12307. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12308. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12309. fclose(fp);
  12310. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12311. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12312. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12313. sendCertificateSignedConfirmation(uuid);
  12314. return result;
  12315. }
  12316. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12317. {
  12318. mtrace();
  12319. int result = PASS;
  12320. json_object *DeleteCertificate;
  12321. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12322. DeleteCertificate = json_tokener_parse(payload);
  12323. if(!is_error(DeleteCertificate))
  12324. {
  12325. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12326. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12327. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12328. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12329. }
  12330. json_object_put(DeleteCertificate);
  12331. /*
  12332. * TODO: Delete certificateSigned process
  12333. */
  12334. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12335. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12336. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12337. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12338. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12339. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12340. sendDeleteCertificateConfirmation(uuid);
  12341. return result;
  12342. }
  12343. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12344. {
  12345. mtrace();
  12346. int result = PASS;
  12347. json_object *ExtendedTriggerMessage;
  12348. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12349. ExtendedTriggerMessage = json_tokener_parse(payload);
  12350. if(!is_error(ExtendedTriggerMessage))
  12351. {
  12352. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12353. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12354. {
  12355. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12356. }
  12357. else
  12358. {
  12359. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12360. }
  12361. }
  12362. json_object_put(ExtendedTriggerMessage);
  12363. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12364. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12365. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12366. {
  12367. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12368. }
  12369. else
  12370. {
  12371. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12372. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12373. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12374. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12375. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12376. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12377. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12378. {
  12379. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12380. }
  12381. else
  12382. {
  12383. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12384. }
  12385. }
  12386. sendExtendedTriggerMessageConfirmation(uuid);
  12387. //==========================
  12388. // Trigger message
  12389. //==========================
  12390. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12391. {
  12392. //sendBootNotificationRequest();
  12393. server_sign = FALSE;
  12394. }
  12395. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12396. {
  12397. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12398. }
  12399. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12400. {
  12401. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12402. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12403. {
  12404. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12405. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12406. }
  12407. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12408. }
  12409. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12410. {
  12411. refreshStartTimer(&clientTime.Heartbeat);
  12412. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12413. }
  12414. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12415. {
  12416. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12417. {
  12418. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12419. }
  12420. else
  12421. {
  12422. for(int idx=0;idx< gunTotalNumber;idx++)
  12423. {
  12424. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12425. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12426. }
  12427. }
  12428. }
  12429. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12430. {
  12431. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12432. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12433. {
  12434. 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\" &");
  12435. }
  12436. }
  12437. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12438. {
  12439. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12440. {
  12441. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12442. }
  12443. else
  12444. {
  12445. for(int idx=0;idx< gunTotalNumber;idx++)
  12446. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12447. }
  12448. }
  12449. return result;
  12450. }
  12451. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12452. {
  12453. mtrace();
  12454. int result = PASS;
  12455. json_object *GetInstalledCertificateIds;
  12456. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12457. GetInstalledCertificateIds = json_tokener_parse(payload);
  12458. if(!is_error(GetInstalledCertificateIds))
  12459. {
  12460. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12461. }
  12462. json_object_put(GetInstalledCertificateIds);
  12463. /*
  12464. * TODO: Return installed certificate process
  12465. */
  12466. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12467. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12468. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12469. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12470. sendGetInstalledCertificateIdsConfirmation(uuid);
  12471. return result;
  12472. }
  12473. int handleGetLogRequest(char *uuid, char *payload)
  12474. {
  12475. mtrace();
  12476. int result = PASS;
  12477. json_object *GetLog;
  12478. DEBUG_INFO("handleGetLogRequest...\n");
  12479. GetLog = json_tokener_parse(payload);
  12480. if(!is_error(GetLog))
  12481. {
  12482. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12483. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12484. if(json_object_object_get(GetLog, "retries") != NULL)
  12485. {
  12486. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12487. }
  12488. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12489. {
  12490. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12491. }
  12492. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12493. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12494. {
  12495. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12496. }
  12497. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12498. {
  12499. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12500. }
  12501. }
  12502. json_object_put(GetLog);
  12503. /*
  12504. * TODO: Upload log process
  12505. */
  12506. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12507. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12508. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12509. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12510. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12511. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12512. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12513. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12514. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12515. sendGetLogConfirmation(uuid);
  12516. return result;
  12517. }
  12518. int handleInstallCertificateRequest(char *uuid, char *payload)
  12519. {
  12520. mtrace();
  12521. int result = PASS;
  12522. json_object *InstallCertificate;
  12523. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12524. InstallCertificate = json_tokener_parse(payload);
  12525. if(!is_error(InstallCertificate))
  12526. {
  12527. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12528. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12529. /*
  12530. * TODO: Install certificate process
  12531. */
  12532. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12533. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12534. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12535. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12536. sendInstallCertificateConfirmation(uuid);
  12537. }
  12538. json_object_put(InstallCertificate);
  12539. return result;
  12540. }
  12541. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12542. {
  12543. mtrace();
  12544. int result = PASS;
  12545. json_object *SignedUpdateFirmware;
  12546. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12547. SignedUpdateFirmware = json_tokener_parse(payload);
  12548. if(!is_error(SignedUpdateFirmware))
  12549. {
  12550. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12551. {
  12552. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12553. }
  12554. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12555. {
  12556. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12557. }
  12558. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12559. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12560. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12561. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12562. {
  12563. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12564. }
  12565. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12566. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12567. }
  12568. json_object_put(SignedUpdateFirmware);
  12569. /*
  12570. * TODO: Upgrade firmware process
  12571. */
  12572. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12573. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12574. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12575. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12576. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12577. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12578. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12579. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12580. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12581. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12582. sendInstallCertificateConfirmation(uuid);
  12583. return result;
  12584. }
  12585. int handleUnknownRequest(char *uuid, char *payload)
  12586. {
  12587. mtrace();
  12588. int result = PASS;
  12589. DEBUG_INFO("handleUnknownRequest...\n");
  12590. sendUnknownConfirmation(uuid);
  12591. result = PASS;
  12592. return result;
  12593. }
  12594. //==========================================
  12595. // Handle server response routine
  12596. //==========================================
  12597. void handleAuthorizeResponse(char *payload, int gun_index)
  12598. {
  12599. mtrace();
  12600. char expiryDatestr[30]={0};
  12601. char parentIdTagstr[20]={0};
  12602. char statusstr[20]={0};
  12603. int expiryDateISNULL=FALSE;
  12604. int parentIdTagISNULL=FALSE;
  12605. DEBUG_INFO("handleAuthorizeResponse...\n");
  12606. json_object *Authorize;
  12607. Authorize = json_tokener_parse(payload);
  12608. if(!is_error(Authorize))
  12609. {
  12610. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12611. {
  12612. // Required data
  12613. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12614. // Optional data
  12615. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12616. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12617. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12618. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12619. }
  12620. }
  12621. json_object_put(Authorize);
  12622. if(expiryDateISNULL == FALSE)
  12623. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12624. if(parentIdTagISNULL == FALSE)
  12625. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12626. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12627. //Update idTag information to authorization cache if supproted
  12628. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12629. {
  12630. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12631. }
  12632. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12633. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12634. authorizeRetryTimes = 0;
  12635. }
  12636. void handleBootNotificationResponse(char *payload, int gun_index)
  12637. {
  12638. mtrace();
  12639. char statusStr[12]={0};
  12640. char currentTimeStr[30]={0};
  12641. int intervalInt = 0;
  12642. DEBUG_INFO("handleBootNotificationResponse...\n");
  12643. json_object *BootNotification;
  12644. BootNotification = json_tokener_parse(payload);
  12645. if(!is_error(BootNotification))
  12646. {
  12647. // Required data
  12648. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12649. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12650. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12651. }
  12652. json_object_put(BootNotification);
  12653. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12654. BootNotificationInterval = intervalInt;
  12655. HeartBeatWaitTime = intervalInt;
  12656. //write back to ShmOCPP16DataPH->BootNotification
  12657. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12658. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12659. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12660. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12661. {
  12662. if((intervalInt == 0) || (intervalInt >= 10))
  12663. {
  12664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12665. HeartBeatWaitTime = intervalInt;
  12666. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12667. }
  12668. server_sign = TRUE;
  12669. server_pending =FALSE;
  12670. }
  12671. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12672. {
  12673. server_pending = TRUE;
  12674. }
  12675. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12676. srand(time(NULL));
  12677. refreshStartTimer(&clientTime.Heartbeat);
  12678. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12679. SetOcppConnStatus(TRUE);
  12680. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12681. }
  12682. void handleDataTransferResponse(char *payload, int gun_index)
  12683. {
  12684. char sstr[160]={0};//sstr[200]={ 0 };
  12685. int c = 0;
  12686. char *loc;
  12687. DEBUG_INFO("handleDataTransferResponse ...\n");
  12688. loc = strstr(payload, "status");
  12689. c = 0;
  12690. while (loc[3+strlen("status")+c] != '\"')
  12691. {
  12692. sstr[c] = loc[3+strlen("status")+c];
  12693. c++;
  12694. }
  12695. sstr[c] = '\0';
  12696. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12697. }
  12698. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12699. {
  12700. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12701. //struct json_object *obj;
  12702. // obj = json_tokener_parse(payload);
  12703. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12704. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12705. //No fields are defined.
  12706. }
  12707. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12708. {
  12709. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12710. //struct json_object *obj;
  12711. // obj = json_tokener_parse(payload);
  12712. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12713. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12714. //No fields are defined.
  12715. }
  12716. void handleHeartbeatResponse(char *payload, int gun_index)
  12717. {
  12718. mtrace();
  12719. DEBUG_INFO("handleHeartbeatResponse...\n");
  12720. json_object *Heartbeat;
  12721. Heartbeat = json_tokener_parse(payload);
  12722. if(!is_error(Heartbeat))
  12723. {
  12724. // Required data
  12725. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12726. }
  12727. json_object_put(Heartbeat);
  12728. if(FirstHeartBeat == 0)
  12729. {
  12730. FirstHeartBeat = 1;
  12731. DEBUG_INFO("FirstHeartBeat \n");
  12732. }
  12733. HeartBeatWithNOResponse = 0;
  12734. refreshStartTimer(&clientTime.Heartbeat);
  12735. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12736. }
  12737. void handleMeterValuesResponse(char *payload, int gun_index)
  12738. {
  12739. mtrace();
  12740. DEBUG_INFO("handleMeterValuesResponse...\n");
  12741. isQueueSendable = 1;
  12742. }
  12743. void handleStartTransactionResponse(char *payload, int gun_index)
  12744. {
  12745. mtrace();
  12746. //int transactionIdInt = 0;
  12747. FILE *outfile;
  12748. char data[100]={0};
  12749. DEBUG_INFO("handleStartTransactionResponse...\n");
  12750. json_object *StartTransaction;
  12751. StartTransaction = json_tokener_parse(payload);
  12752. if(!is_error(StartTransaction))
  12753. {
  12754. // Required data
  12755. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12756. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12757. // Optional data
  12758. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12759. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12760. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12761. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12762. }
  12763. json_object_put(StartTransaction);
  12764. isQueueSendable = 1;
  12765. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12766. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12767. //-----------Start : write to the Queue TransactionId file -----------------//
  12768. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12769. {}
  12770. else
  12771. {
  12772. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12773. if(log == NULL)
  12774. {
  12775. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12776. return ;
  12777. }
  12778. else
  12779. {
  12780. fclose(log);
  12781. }
  12782. }
  12783. // open file for writing
  12784. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12785. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12786. {
  12787. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12788. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12789. fputs(data, outfile);
  12790. fclose (outfile);
  12791. }
  12792. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12793. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12794. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12795. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12796. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12797. }
  12798. void handleStatusNotificationResponse(char *payload, int gun_index)
  12799. {
  12800. mtrace();
  12801. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12802. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12803. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12804. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12805. }
  12806. void handleStopTransactionnResponse(char *payload, int gun_index)
  12807. {
  12808. mtrace();
  12809. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12810. json_object *StopTransaction;
  12811. StopTransaction = json_tokener_parse(payload);
  12812. if(!is_error(StopTransaction))
  12813. {
  12814. // Optional data
  12815. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12816. {
  12817. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12818. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12819. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12820. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12821. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12822. }
  12823. }
  12824. json_object_put(StopTransaction);
  12825. isQueueSendable = 1;
  12826. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12827. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12828. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12829. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12830. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12831. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12832. }
  12833. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12834. {
  12835. mtrace();
  12836. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12837. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12838. }
  12839. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12840. {
  12841. mtrace();
  12842. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12843. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12844. }
  12845. void handleSignCertificateResponse(char *payload, int gun_index)
  12846. {
  12847. mtrace();
  12848. DEBUG_INFO("handleSignCertificateResponse...\n");
  12849. json_object *SignCertificate;
  12850. SignCertificate = json_tokener_parse(payload);
  12851. if(!is_error(SignCertificate))
  12852. {
  12853. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12854. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12855. }
  12856. json_object_put(SignCertificate);
  12857. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12858. }
  12859. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12860. {
  12861. mtrace();
  12862. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12863. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12864. }
  12865. //==========================================
  12866. // Handle Error routine
  12867. //==========================================
  12868. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12869. {
  12870. mtrace();
  12871. #ifdef SystemLogMessage
  12872. DEBUG_INFO("errorCode: %s\n", errorCode);
  12873. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12874. DEBUG_INFO("errorDetails: %s\n", payload);
  12875. #endif
  12876. }
  12877. //===============================================
  12878. // Common routine
  12879. //===============================================
  12880. int initialConfigurationTable(void)
  12881. {
  12882. //clock_t start_t, end_t, total_t;
  12883. FILE *fp;
  12884. FILE *outfile;
  12885. char str[512]={0};
  12886. char sstr[256]={0};
  12887. int c = 0;
  12888. char *loc;
  12889. int confVersion = 11;
  12890. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12891. //start_t = clock();
  12892. //printf("Starting of the program, start_t = %ld\n", start_t);
  12893. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12894. // Check configuration file size is correct
  12895. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12896. {
  12897. struct stat st;
  12898. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12899. if(st.st_size < 3100)
  12900. {
  12901. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12902. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12903. }
  12904. }
  12905. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12906. {
  12907. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12908. if(outfile == NULL)
  12909. {
  12910. DEBUG_INFO("Error opening file\n");
  12911. return FALSE;
  12912. }
  12913. /*Core Profile*/
  12914. //AllowOfflineTxForUnknownId
  12915. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12919. //AuthorizationCacheEnabled
  12920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12924. //AuthorizeRemoteTxRequests
  12925. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12929. //BlinkRepeat
  12930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12934. //ClockAlignedDataInterval
  12935. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12939. //ConnectionTimeOut
  12940. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12944. //GetConfigurationMaxKeys
  12945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12947. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12949. // HeartbeatInterval
  12950. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12954. // LightIntensity
  12955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12959. // LocalAuthorizeOffline
  12960. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12964. // LocalPreAuthorize
  12965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12969. // MaxEnergyOnInvalidId
  12970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12974. // MeterValuesAlignedData
  12975. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12978. 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" );
  12979. else
  12980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12982. // MeterValuesAlignedDataMaxLength
  12983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12985. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12987. else
  12988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12990. // MeterValuesSampledData
  12991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12994. 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" );
  12995. else
  12996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12998. // MeterValuesSampledDataMaxLength
  12999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13003. else
  13004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13006. // MeterValueSampleInterval
  13007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13011. // MinimumStatusDuration
  13012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13015. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13017. // NumberOfConnectors
  13018. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13021. {
  13022. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13023. }
  13024. else
  13025. {
  13026. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13027. }
  13028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13029. // ResetRetries
  13030. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13032. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13034. // ConnectorPhaseRotation
  13035. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13039. // ConnectorPhaseRotationMaxLength
  13040. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13044. // StopTransactionOnEVSideDisconnect
  13045. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13049. // StopTransactionOnInvalidId
  13050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13054. // StopTxnAlignedData
  13055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13059. // StopTxnAlignedDataMaxLength
  13060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13064. // StopTxnSampledData
  13065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13069. else
  13070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13072. // StopTxnSampledDataMaxLength
  13073. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13074. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13075. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13076. {
  13077. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13078. }
  13079. else
  13080. {
  13081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13082. }
  13083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13084. // SupportedFeatureProfiles
  13085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13089. // SupportedFeatureProfilesMaxLength
  13090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13094. // TransactionMessageAttempts
  13095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13098. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13100. // TransactionMessageRetryInterval
  13101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13104. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13106. // UnlockConnectorOnEVSideDisconnect
  13107. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13111. // WebSocketPingInterval
  13112. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13116. // QueueOffLineMeterValues
  13117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13121. // AuthorizationKey
  13122. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13126. // SecurityProfile
  13127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13129. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13131. // DefaultPrice
  13132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13136. // CustomDisplayCostAndPrice
  13137. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13141. // CustomIdleFeeAfterStop
  13142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13146. // SystemUptimeSec
  13147. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13151. // FreeVend
  13152. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13156. // OcppServer
  13157. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13159. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13161. // MaintainServer
  13162. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13164. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13166. // Configuration Version
  13167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13169. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13171. //* Local Auth List Management Profile*/
  13172. #if 0
  13173. //For OCTT Test Case
  13174. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13177. #endif
  13178. #if 1
  13179. //LocalAuthListEnabled
  13180. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13184. #endif
  13185. //LocalAuthListMaxLength
  13186. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13190. //SendLocalListMaxLength
  13191. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13195. //ReserveConnectorZeroSupported
  13196. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13200. //* Smart Charging Profile */
  13201. //ChargeProfileMaxStackLevel
  13202. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13206. // ChargingScheduleAllowedChargingRateUnit
  13207. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13211. // ChargingScheduleMaxPeriods
  13212. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13216. // ConnectorSwitch3to1PhaseSupported
  13217. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13221. // MaxChargingProfilesInstalled
  13222. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13226. fclose(outfile);
  13227. }
  13228. else
  13229. {
  13230. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13231. char keystr[60]={0};
  13232. char readonlystr[10]={0};
  13233. char valuestr[256]={0};
  13234. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13235. if(fp == NULL) {
  13236. DEBUG_INFO("Error opening file");
  13237. return FALSE;
  13238. }
  13239. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13240. {
  13241. //DEBUG_INFO("Get Configuration \n");
  13242. if(strlen(str) > 0)
  13243. {
  13244. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13245. //*************************key*********************************/
  13246. if(strstr(str, "key") != NULL)
  13247. {
  13248. loc = strstr(str, "key");
  13249. c = 0;
  13250. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13251. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13252. {
  13253. sstr[c] = loc[strlen("key")+3+c];
  13254. c++;
  13255. }
  13256. sstr[c] = '\0';
  13257. strcpy(keystr,sstr);
  13258. }
  13259. //*************************readonly*********************************/
  13260. if(strstr(str, "readonly") != NULL)
  13261. {
  13262. loc = strstr(str, "readonly");
  13263. c = 0;
  13264. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13265. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13266. {
  13267. sstr[c] = loc[strlen("readonly")+2+c];
  13268. c++;
  13269. }
  13270. sstr[c] = '\0';
  13271. strcpy(readonlystr,sstr);
  13272. }
  13273. //*************************value*********************************/
  13274. if(strstr(str, "value") != NULL)
  13275. {
  13276. loc = strstr(str, "value");
  13277. c = 0;
  13278. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13279. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13280. {
  13281. sstr[c] = loc[strlen("value")+3+c];
  13282. c++;
  13283. }
  13284. sstr[c] = '\0';
  13285. strcpy(valuestr,sstr);
  13286. }
  13287. // DEBUG_INFO("keystr=%s\n",keystr);
  13288. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13289. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13290. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13291. {
  13292. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13294. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13295. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13296. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13297. }
  13298. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13299. {
  13300. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13303. }
  13304. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13305. {
  13306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13308. }
  13309. if(strcmp(keystr, "BlinkRepeat") == 0)
  13310. {
  13311. //Charger.BlinkRepeat = Integer.parseInt(value);
  13312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13314. }
  13315. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13316. {
  13317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13319. }
  13320. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13321. {
  13322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13324. }
  13325. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13326. {
  13327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13329. }
  13330. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13331. {
  13332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13334. HeartBeatWaitTime = atoi(valuestr);
  13335. }
  13336. if(strcmp(keystr, "LightIntensity") == 0)
  13337. {
  13338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13340. }
  13341. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13342. {
  13343. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13345. }
  13346. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13347. {
  13348. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13350. }
  13351. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13352. {
  13353. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13355. }
  13356. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13357. {
  13358. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13359. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13360. }
  13361. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13362. {
  13363. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13364. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13365. }
  13366. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13367. {
  13368. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13369. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13370. }
  13371. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13372. {
  13373. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13374. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13375. }
  13376. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13377. {
  13378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13379. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13380. }
  13381. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13382. {
  13383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13384. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13385. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13386. }
  13387. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13388. {
  13389. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13391. }
  13392. if(strcmp(keystr, "ResetRetries") == 0)
  13393. {
  13394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13396. }
  13397. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13398. {
  13399. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13401. }
  13402. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13403. {
  13404. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13405. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13406. }
  13407. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13408. {
  13409. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13410. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13411. }
  13412. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13413. {
  13414. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13415. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13416. }
  13417. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13418. {
  13419. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13420. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13421. }
  13422. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13423. {
  13424. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13425. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13426. }
  13427. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13428. {
  13429. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13430. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13431. }
  13432. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13433. {
  13434. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13435. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13436. }
  13437. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13438. {
  13439. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13440. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13441. }
  13442. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13443. {
  13444. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13445. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13446. }
  13447. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13448. {
  13449. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13450. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13451. TransactionMessageAttemptsValue = atoi(valuestr);
  13452. }
  13453. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13454. {
  13455. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13456. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13457. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13458. }
  13459. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13460. {
  13461. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13462. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13463. }
  13464. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13465. {
  13466. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13468. }
  13469. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13470. {
  13471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13472. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13473. }
  13474. if(strcmp(keystr, "AuthorizationKey") == 0)
  13475. {
  13476. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13477. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13479. }
  13480. if(strcmp(keystr, "SecurityProfile") == 0)
  13481. {
  13482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13483. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13484. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13485. }
  13486. if(strcmp(keystr, "DefaultPrice") == 0)
  13487. {
  13488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13490. }
  13491. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13492. {
  13493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13495. }
  13496. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13497. {
  13498. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13499. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13500. }
  13501. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13502. {
  13503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13504. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13505. }
  13506. if(strcmp(keystr, "FreeVend") == 0)
  13507. {
  13508. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13509. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13510. }
  13511. if(strcmp(keystr, "OcppServer") == 0)
  13512. {
  13513. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13514. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13515. }
  13516. if(strcmp(keystr, "MaintainServer") == 0)
  13517. {
  13518. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13519. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13520. }
  13521. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13522. {
  13523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13525. }
  13526. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13527. {
  13528. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13530. }
  13531. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13532. {
  13533. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13534. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13535. }
  13536. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13537. {
  13538. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13540. }
  13541. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13542. {
  13543. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13545. }
  13546. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13547. {
  13548. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13550. }
  13551. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13552. {
  13553. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13554. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13555. }
  13556. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13557. {
  13558. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13560. }
  13561. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13562. {
  13563. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13565. }
  13566. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13567. {
  13568. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13570. }
  13571. }
  13572. }
  13573. fclose(fp);
  13574. }
  13575. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13576. {
  13577. return PASS;
  13578. }
  13579. else
  13580. {
  13581. return FAIL;
  13582. }
  13583. }
  13584. void StoreConfigurationTable(void)
  13585. {
  13586. FILE *outfile;
  13587. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13588. if(outfile == NULL)
  13589. {
  13590. DEBUG_INFO("Error opening file");
  13591. return ;
  13592. }
  13593. /*Core Profile*/
  13594. //AllowOfflineTxForUnknownId
  13595. /*
  13596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13597. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13600. */
  13601. //DEBUG_INFO("data=%s\n",data);
  13602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13603. //AuthorizationCacheEnabled
  13604. /*
  13605. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13608. */
  13609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13610. //AuthorizeRemoteTxRequests
  13611. /*
  13612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13615. */
  13616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13617. //BlinkRepeat
  13618. /*
  13619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13621. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13622. */
  13623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13624. //ClockAlignedDataInterval
  13625. /*
  13626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13629. */
  13630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13631. //ConnectionTimeOut
  13632. /*
  13633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13636. */
  13637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13638. //GetConfigurationMaxKeys
  13639. /*
  13640. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13643. */
  13644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13645. // HeartbeatInterval
  13646. /*
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13650. */
  13651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13652. // LightIntensity
  13653. /*
  13654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13657. */
  13658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13659. // LocalAuthorizeOffline
  13660. /*
  13661. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13663. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13664. */
  13665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13666. // LocalPreAuthorize
  13667. /*
  13668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13671. */
  13672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13673. // MaxEnergyOnInvalidId
  13674. /*
  13675. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13677. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13678. */
  13679. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13681. // MeterValuesAlignedData
  13682. /*
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13686. */
  13687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13688. // MeterValuesAlignedDataMaxLength
  13689. /*
  13690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13691. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13692. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13693. */
  13694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13695. // MeterValuesSampledData
  13696. /*
  13697. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13699. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13700. */
  13701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13702. // MeterValuesSampledDataMaxLength
  13703. /*
  13704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13706. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13707. */
  13708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13709. // MeterValueSampleInterval
  13710. /*
  13711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13713. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13714. */
  13715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13716. // MinimumStatusDuration
  13717. /*
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13720. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13721. */
  13722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13723. // NumberOfConnectors
  13724. /*
  13725. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13728. {
  13729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13730. }
  13731. else
  13732. {
  13733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13734. }
  13735. */
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13737. // ResetRetries
  13738. /*
  13739. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13742. */
  13743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13744. // ConnectorPhaseRotation
  13745. /*
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13749. */
  13750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13751. // ConnectorPhaseRotationMaxLength
  13752. /*
  13753. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13756. */
  13757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13758. // StopTransactionOnEVSideDisconnect
  13759. /*
  13760. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13761. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13762. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13763. */
  13764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13765. // StopTransactionOnInvalidId
  13766. /*
  13767. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13770. */
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13772. // StopTxnAlignedData
  13773. /*
  13774. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13776. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13777. */
  13778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13779. // StopTxnAlignedDataMaxLength
  13780. /*
  13781. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13783. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13784. */
  13785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13786. // StopTxnSampledData
  13787. /*
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13791. */
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13793. // StopTxnSampledDataMaxLength
  13794. /*
  13795. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13798. */
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13800. // SupportedFeatureProfiles
  13801. /*
  13802. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13803. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13805. */
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13807. // SupportedFeatureProfilesMaxLength
  13808. /*
  13809. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13811. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13812. */
  13813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13814. // TransactionMessageAttempts
  13815. /*
  13816. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13818. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13819. */
  13820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13821. // TransactionMessageRetryInterval
  13822. /*
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13826. */
  13827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13828. // UnlockConnectorOnEVSideDisconnect
  13829. /*
  13830. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13833. */
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13835. // WebSocketPingInterval
  13836. /*
  13837. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13840. */
  13841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13842. // QueueOffLineMeterValues
  13843. /*
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13847. */
  13848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13849. // AuthorizationKey
  13850. /*
  13851. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13854. */
  13855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13856. // SecurityProfile
  13857. /*
  13858. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13861. */
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13863. // DefaultPrice
  13864. /*
  13865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13868. */
  13869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13870. // CustomDisplayCostAndPrice
  13871. /*
  13872. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13875. */
  13876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13877. // CustomIdleFeeAfterStop
  13878. /*
  13879. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13882. */
  13883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13884. // SystemUptimeSec
  13885. /*
  13886. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13889. */
  13890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13891. // FreeVend
  13892. /*
  13893. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13896. */
  13897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13898. // OcppServer
  13899. /*
  13900. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  13903. */
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13905. // MaintainServer
  13906. /*
  13907. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  13910. */
  13911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13912. // ConfigurationVersion
  13913. /*
  13914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13917. */
  13918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13919. //* Local Auth List Management Profile*/
  13920. //LocalAuthListEnabled
  13921. /*
  13922. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13925. */
  13926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13927. //LocalAuthListMaxLength
  13928. /*
  13929. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13932. */
  13933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13934. //SendLocalListMaxLength
  13935. /*
  13936. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13939. */
  13940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13941. //ReserveConnectorZeroSupported
  13942. /*
  13943. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13946. */
  13947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13948. //* Smart Charging Profile */
  13949. //ChargeProfileMaxStackLevel
  13950. /*
  13951. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13954. */
  13955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13956. // ChargingScheduleAllowedChargingRateUnit
  13957. /*
  13958. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13961. */
  13962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13963. // ChargingScheduleMaxPeriods
  13964. /*
  13965. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13968. */
  13969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13970. // ConnectorSwitch3to1PhaseSupported
  13971. /*
  13972. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13975. */
  13976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13977. // MaxChargingProfilesInstalled
  13978. /*
  13979. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13982. */
  13983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13984. fclose(outfile);
  13985. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13986. }
  13987. void getKeyValue(char *keyReq)
  13988. {
  13989. int isEmpty = FALSE;
  13990. int isKnowKey = FALSE;
  13991. DEBUG_INFO("keyReq = %s\n", keyReq);
  13992. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13993. isEmpty = TRUE;
  13994. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13995. {
  13996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13998. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13999. {
  14000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14001. }
  14002. else
  14003. {
  14004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14005. }
  14006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14007. isKnowKey = TRUE;
  14008. }
  14009. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14010. {
  14011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14013. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14014. {
  14015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14016. }
  14017. else
  14018. {
  14019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14020. }
  14021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14022. isKnowKey = TRUE;
  14023. }
  14024. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14025. {
  14026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14028. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14029. {
  14030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14031. }
  14032. else
  14033. {
  14034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14035. }
  14036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14037. isKnowKey = TRUE;
  14038. }
  14039. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14040. {
  14041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14043. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14044. {
  14045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14046. }
  14047. else
  14048. {
  14049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14050. }
  14051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14052. isKnowKey = TRUE;
  14053. }
  14054. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14055. {
  14056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14058. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14059. {
  14060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14061. }
  14062. else
  14063. {
  14064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14065. }
  14066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14067. isKnowKey = TRUE;
  14068. }
  14069. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14070. {
  14071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14073. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14074. {
  14075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14076. }
  14077. else
  14078. {
  14079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14080. }
  14081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14082. isKnowKey = TRUE;
  14083. }
  14084. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14085. {
  14086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14088. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14089. {
  14090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14091. }
  14092. else
  14093. {
  14094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14095. }
  14096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14097. isKnowKey = TRUE;
  14098. }
  14099. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14100. {
  14101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14103. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14104. {
  14105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14106. }
  14107. else
  14108. {
  14109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14110. }
  14111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14112. isKnowKey = TRUE;
  14113. }
  14114. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14115. {
  14116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14118. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14119. {
  14120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14121. }
  14122. else
  14123. {
  14124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14125. }
  14126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14127. isKnowKey = TRUE;
  14128. }
  14129. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14130. {
  14131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14133. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14134. {
  14135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14136. }
  14137. else
  14138. {
  14139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14140. }
  14141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14142. isKnowKey = TRUE;
  14143. }
  14144. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14145. {
  14146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14148. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14149. {
  14150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14151. }
  14152. else
  14153. {
  14154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14155. }
  14156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14157. isKnowKey = TRUE;
  14158. }
  14159. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14160. {
  14161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14163. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14164. {
  14165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14166. }
  14167. else
  14168. {
  14169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14170. }
  14171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14172. isKnowKey = TRUE;
  14173. }
  14174. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14175. {
  14176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14178. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14179. {
  14180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14181. }
  14182. else
  14183. {
  14184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14185. }
  14186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14187. isKnowKey = TRUE;
  14188. }
  14189. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14190. {
  14191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14193. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14194. {
  14195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14196. }
  14197. else
  14198. {
  14199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14200. }
  14201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14202. isKnowKey = TRUE;
  14203. }
  14204. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14205. {
  14206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14208. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14209. {
  14210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14211. }
  14212. else
  14213. {
  14214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14215. }
  14216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14217. isKnowKey = TRUE;
  14218. }
  14219. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14220. {
  14221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14223. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14224. {
  14225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14226. }
  14227. else
  14228. {
  14229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14230. }
  14231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14232. isKnowKey = TRUE;
  14233. }
  14234. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14235. {
  14236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14238. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14239. {
  14240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14241. }
  14242. else
  14243. {
  14244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14245. }
  14246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14247. isKnowKey = TRUE;
  14248. }
  14249. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14250. {
  14251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14253. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14254. {
  14255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14256. }
  14257. else
  14258. {
  14259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14260. }
  14261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14262. isKnowKey = TRUE;
  14263. }
  14264. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14265. {
  14266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14268. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14269. {
  14270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14271. }
  14272. else
  14273. {
  14274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14275. }
  14276. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14278. isKnowKey = TRUE;
  14279. }
  14280. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14281. {
  14282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14284. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14285. {
  14286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14287. }
  14288. else
  14289. {
  14290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14291. }
  14292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14293. isKnowKey = TRUE;
  14294. }
  14295. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14296. {
  14297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14299. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14300. {
  14301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14302. }
  14303. else
  14304. {
  14305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14306. }
  14307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14308. isKnowKey = TRUE;
  14309. }
  14310. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14311. {
  14312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14314. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14315. {
  14316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14317. }
  14318. else
  14319. {
  14320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14321. }
  14322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14323. isKnowKey = TRUE;
  14324. }
  14325. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14326. {
  14327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14329. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14330. {
  14331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14332. }
  14333. else
  14334. {
  14335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14336. }
  14337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14338. isKnowKey = TRUE;
  14339. }
  14340. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14341. {
  14342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14344. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14345. {
  14346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14347. }
  14348. else
  14349. {
  14350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14351. }
  14352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14353. isKnowKey = TRUE;
  14354. }
  14355. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14356. {
  14357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14360. {
  14361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14362. }
  14363. else
  14364. {
  14365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14366. }
  14367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14368. isKnowKey = TRUE;
  14369. }
  14370. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14371. {
  14372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14374. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14375. {
  14376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14377. }
  14378. else
  14379. {
  14380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14381. }
  14382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14383. isKnowKey = TRUE;
  14384. }
  14385. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14386. {
  14387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14389. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14390. {
  14391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14392. }
  14393. else
  14394. {
  14395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14396. }
  14397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14398. isKnowKey = TRUE;
  14399. }
  14400. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14401. {
  14402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14404. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14405. {
  14406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14407. }
  14408. else
  14409. {
  14410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14411. }
  14412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14413. isKnowKey = TRUE;
  14414. }
  14415. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14416. {
  14417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14419. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14420. {
  14421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14422. }
  14423. else
  14424. {
  14425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14426. }
  14427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14428. isKnowKey = TRUE;
  14429. }
  14430. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14431. {
  14432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14434. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14435. {
  14436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14437. }
  14438. else
  14439. {
  14440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14441. }
  14442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14443. isKnowKey = TRUE;
  14444. }
  14445. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14446. {
  14447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14449. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14450. {
  14451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14452. }
  14453. else
  14454. {
  14455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14456. }
  14457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14458. isKnowKey = TRUE;
  14459. }
  14460. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14461. {
  14462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14465. {
  14466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14467. }
  14468. else
  14469. {
  14470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14471. }
  14472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14473. isKnowKey = TRUE;
  14474. }
  14475. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14476. {
  14477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14479. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14480. {
  14481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14482. }
  14483. else
  14484. {
  14485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14486. }
  14487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14488. isKnowKey = TRUE;
  14489. }
  14490. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14491. {
  14492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14494. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14495. {
  14496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14497. }
  14498. else
  14499. {
  14500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14501. }
  14502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14503. isKnowKey = TRUE;
  14504. }
  14505. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14506. {
  14507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14509. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14510. {
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14512. }
  14513. else
  14514. {
  14515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14516. }
  14517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14518. isKnowKey = TRUE;
  14519. }
  14520. /*
  14521. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14522. {
  14523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14525. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14526. {
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14528. }
  14529. else
  14530. {
  14531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14532. }
  14533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14534. isKnowKey = TRUE;
  14535. }*/
  14536. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14537. {
  14538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14540. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14541. {
  14542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14543. }
  14544. else
  14545. {
  14546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14547. }
  14548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14549. isKnowKey = TRUE;
  14550. }
  14551. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14552. {
  14553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14555. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14556. {
  14557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14558. }
  14559. else
  14560. {
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14562. }
  14563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14564. isKnowKey = TRUE;
  14565. }
  14566. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14567. {
  14568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14570. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14571. {
  14572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14573. }
  14574. else
  14575. {
  14576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14577. }
  14578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14579. isKnowKey = TRUE;
  14580. }
  14581. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14582. {
  14583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14585. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14586. {
  14587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14588. }
  14589. else
  14590. {
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14592. }
  14593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14594. isKnowKey = TRUE;
  14595. }
  14596. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14597. {
  14598. struct sysinfo s_info;
  14599. int error = sysinfo(&s_info);
  14600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14603. {
  14604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14605. }
  14606. else
  14607. {
  14608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14609. }
  14610. if(error != 0)
  14611. {
  14612. DEBUG_WARN("System uptime get error: %d\n", error);
  14613. }
  14614. else
  14615. {
  14616. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14617. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14618. }
  14619. isKnowKey = TRUE;
  14620. }
  14621. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14622. {
  14623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14625. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14626. {
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14628. }
  14629. else
  14630. {
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14632. }
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14634. isKnowKey = TRUE;
  14635. }
  14636. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14637. {
  14638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14641. {
  14642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14643. }
  14644. else
  14645. {
  14646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14647. }
  14648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14649. isKnowKey = TRUE;
  14650. }
  14651. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14652. {
  14653. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14656. {
  14657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14658. }
  14659. else
  14660. {
  14661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14662. }
  14663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14664. isKnowKey = TRUE;
  14665. }
  14666. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14667. {
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14671. {
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14673. }
  14674. else
  14675. {
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14677. }
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14679. isKnowKey = TRUE;
  14680. }
  14681. #if 1
  14682. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14683. {
  14684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14686. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14687. {
  14688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14689. }
  14690. else
  14691. {
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14693. }
  14694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14695. isKnowKey = TRUE;
  14696. }
  14697. #endif
  14698. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14702. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14703. {
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14705. }
  14706. else
  14707. {
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14709. }
  14710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14711. isKnowKey = TRUE;
  14712. }
  14713. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14714. {
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14717. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14718. {
  14719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14720. }
  14721. else
  14722. {
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14724. }
  14725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14726. isKnowKey = TRUE;
  14727. }
  14728. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14729. {
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14732. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14733. {
  14734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14735. }
  14736. else
  14737. {
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14739. }
  14740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14741. isKnowKey = TRUE;
  14742. }
  14743. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14744. {
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14747. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14748. {
  14749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14750. }
  14751. else
  14752. {
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14754. }
  14755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14756. isKnowKey = TRUE;
  14757. }
  14758. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14759. {
  14760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14762. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14763. {
  14764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14765. }
  14766. else
  14767. {
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14769. }
  14770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14771. isKnowKey = TRUE;
  14772. }
  14773. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14774. {
  14775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14777. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14778. {
  14779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14780. }
  14781. else
  14782. {
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14784. }
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14786. isKnowKey = TRUE;
  14787. }
  14788. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14789. {
  14790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14792. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14793. {
  14794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14795. }
  14796. else
  14797. {
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14799. }
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14801. isKnowKey = TRUE;
  14802. }
  14803. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14804. {
  14805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14807. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14808. {
  14809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14810. }
  14811. else
  14812. {
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14814. }
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14816. isKnowKey = TRUE;
  14817. }
  14818. //=========================================================
  14819. if(!isEmpty && !isKnowKey)
  14820. {
  14821. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14822. strcpy(unknownkey[UnknownKeynum], keyReq);
  14823. UnknownKeynum = UnknownKeynum + 1;
  14824. }
  14825. }
  14826. void processUnkownKey(void)
  14827. {
  14828. DEBUG_INFO("processUnkownKey...\n");
  14829. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14830. for(int index=0; index < UnknownKeynum; index++)
  14831. {
  14832. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14833. {
  14834. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14835. }
  14836. }
  14837. }
  14838. int setKeyValue(char *key, char *value)
  14839. {
  14840. int isSuccess = NotSupported;
  14841. int check_ascii=0;
  14842. char str[501]={0};
  14843. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14844. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14845. {
  14846. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14847. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14848. {
  14849. strcpy(str, (const char*)value);
  14850. for(int i = 0; str[i]; i++){
  14851. str[i] = tolower(str[i]);
  14852. }
  14853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14854. isSuccess = ConfigurationStatus_Accepted;
  14855. }
  14856. else
  14857. {
  14858. isSuccess = ConfigurationStatus_Rejected;
  14859. }
  14860. }
  14861. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14862. {
  14863. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14864. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14865. {
  14866. strcpy(str, (const char*)value);
  14867. for(int i = 0; str[i]; i++){
  14868. str[i] = tolower(str[i]);
  14869. }
  14870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14871. isSuccess = ConfigurationStatus_Accepted;
  14872. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  14873. }
  14874. else
  14875. {
  14876. isSuccess = ConfigurationStatus_Rejected;
  14877. }
  14878. }
  14879. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14880. {
  14881. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14882. {
  14883. strcpy(str, (const char*)value);
  14884. for(int i = 0; str[i]; i++)
  14885. {
  14886. str[i] = tolower(str[i]);
  14887. }
  14888. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14889. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14890. isSuccess = ConfigurationStatus_Accepted;
  14891. }
  14892. else
  14893. {
  14894. isSuccess = ConfigurationStatus_Rejected;
  14895. }
  14896. }
  14897. if(strcmp(key, "BlinkRepeat") == 0)
  14898. {
  14899. //Charger.BlinkRepeat = Integer.parseInt(value);
  14900. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14901. {
  14902. check_ascii = value[0];
  14903. if( (check_ascii < 48) || (check_ascii > 57) )
  14904. {
  14905. isSuccess = ConfigurationStatus_Rejected;
  14906. }
  14907. else
  14908. {
  14909. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14910. isSuccess = ConfigurationStatus_Accepted;
  14911. }
  14912. }
  14913. else
  14914. {
  14915. isSuccess = ConfigurationStatus_Rejected;
  14916. }
  14917. }
  14918. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14919. {
  14920. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14921. {
  14922. check_ascii = value[0];
  14923. if( (check_ascii < 48) || (check_ascii > 57) )
  14924. {
  14925. isSuccess = ConfigurationStatus_Rejected;
  14926. }
  14927. else
  14928. {
  14929. if((atoi(value) == 0) || (atoi(value) >= 5))
  14930. {
  14931. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14932. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14933. isSuccess = ConfigurationStatus_Accepted;
  14934. }
  14935. else
  14936. isSuccess = ConfigurationStatus_Rejected;
  14937. }
  14938. }
  14939. else
  14940. {
  14941. isSuccess = ConfigurationStatus_Rejected;
  14942. }
  14943. }
  14944. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14945. {
  14946. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14947. {
  14948. check_ascii = value[0];
  14949. if( (check_ascii < 48) || (check_ascii > 57) )
  14950. {
  14951. isSuccess = ConfigurationStatus_Rejected;
  14952. }
  14953. else
  14954. {
  14955. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14956. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14957. isSuccess = ConfigurationStatus_Accepted;
  14958. }
  14959. }
  14960. else
  14961. {
  14962. isSuccess = ConfigurationStatus_Rejected;
  14963. }
  14964. }
  14965. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14966. {
  14967. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14968. {
  14969. check_ascii = value[0];
  14970. if( (check_ascii < 48) || (check_ascii > 57) )
  14971. {
  14972. isSuccess = ConfigurationStatus_Rejected;
  14973. }
  14974. else
  14975. {
  14976. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14977. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14978. isSuccess = ConfigurationStatus_Accepted;
  14979. }
  14980. }
  14981. else
  14982. {
  14983. isSuccess = ConfigurationStatus_Rejected;
  14984. }
  14985. }
  14986. if(strcmp(key, "HeartbeatInterval") == 0)
  14987. {
  14988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14989. {
  14990. check_ascii = value[0];
  14991. if( (check_ascii < 48) || (check_ascii > 57) )
  14992. {
  14993. isSuccess = ConfigurationStatus_Rejected;
  14994. }
  14995. else
  14996. {
  14997. if((atoi(value) == 0) || (atoi(value) >= 10))
  14998. {
  14999. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15000. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15001. HeartBeatWaitTime = atoi(value);
  15002. isSuccess = ConfigurationStatus_Accepted;
  15003. }
  15004. else
  15005. {
  15006. isSuccess = ConfigurationStatus_Rejected;
  15007. }
  15008. }
  15009. }
  15010. else
  15011. {
  15012. isSuccess = ConfigurationStatus_Rejected;
  15013. }
  15014. }
  15015. if(strcmp(key, "LightIntensity") == 0)
  15016. {
  15017. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15018. {
  15019. check_ascii = value[0];
  15020. if( (check_ascii < 48) || (check_ascii > 57) )
  15021. {
  15022. isSuccess = ConfigurationStatus_Rejected;
  15023. }
  15024. else
  15025. {
  15026. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15027. isSuccess = ConfigurationStatus_Accepted;
  15028. }
  15029. }
  15030. else
  15031. {
  15032. isSuccess = ConfigurationStatus_Rejected;
  15033. }
  15034. }
  15035. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15036. {
  15037. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15038. {
  15039. strcpy(str, (const char*)value);
  15040. for(int i = 0; str[i]; i++)
  15041. {
  15042. str[i] = tolower(str[i]);
  15043. }
  15044. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15045. isSuccess = ConfigurationStatus_Accepted;
  15046. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15047. }
  15048. else
  15049. {
  15050. isSuccess = ConfigurationStatus_Rejected;
  15051. }
  15052. }
  15053. if(strcmp(key, "LocalPreAuthorize") == 0)
  15054. {
  15055. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15056. {
  15057. strcpy(str, (const char*)value);
  15058. for(int i = 0; str[i]; i++)
  15059. {
  15060. str[i] = tolower(str[i]);
  15061. }
  15062. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15063. isSuccess = ConfigurationStatus_Accepted;
  15064. }
  15065. else
  15066. {
  15067. isSuccess = ConfigurationStatus_Rejected;
  15068. }
  15069. }
  15070. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15071. {
  15072. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15073. {
  15074. check_ascii = value[0];
  15075. if( (check_ascii < 48) || (check_ascii > 57) )
  15076. {
  15077. isSuccess = ConfigurationStatus_Rejected;
  15078. }
  15079. else
  15080. {
  15081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15082. isSuccess = ConfigurationStatus_Accepted;
  15083. }
  15084. }
  15085. else
  15086. {
  15087. isSuccess = ConfigurationStatus_Rejected;
  15088. }
  15089. }
  15090. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15091. {
  15092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15093. {
  15094. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15095. isSuccess = ConfigurationStatus_Accepted;
  15096. }
  15097. else
  15098. {
  15099. isSuccess = ConfigurationStatus_Rejected;
  15100. }
  15101. }
  15102. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15103. {
  15104. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15105. {
  15106. check_ascii = value[0];
  15107. if( (check_ascii < 48) || (check_ascii > 57) )
  15108. {
  15109. isSuccess = ConfigurationStatus_Rejected;
  15110. }
  15111. else
  15112. {
  15113. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15114. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15115. isSuccess = ConfigurationStatus_Accepted;
  15116. }
  15117. }
  15118. else
  15119. {
  15120. isSuccess = ConfigurationStatus_Rejected;
  15121. }
  15122. }
  15123. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15124. {
  15125. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15126. {
  15127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15128. isSuccess = ConfigurationStatus_Accepted;
  15129. }
  15130. else
  15131. {
  15132. isSuccess = ConfigurationStatus_Rejected;
  15133. }
  15134. }
  15135. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15136. {
  15137. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15138. {
  15139. check_ascii = value[0];
  15140. if( (check_ascii < 48) || (check_ascii > 57) )
  15141. {
  15142. isSuccess = ConfigurationStatus_Rejected;
  15143. }
  15144. else
  15145. {
  15146. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15148. isSuccess = ConfigurationStatus_Accepted;
  15149. }
  15150. }
  15151. else
  15152. {
  15153. isSuccess = ConfigurationStatus_Rejected;
  15154. }
  15155. }
  15156. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15157. {
  15158. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15159. {
  15160. check_ascii = value[0];
  15161. if( (check_ascii < 48) || (check_ascii > 57) )
  15162. {
  15163. isSuccess = ConfigurationStatus_Rejected;
  15164. }
  15165. else
  15166. {
  15167. if((atoi(value) == 0) || (atoi(value) >= 5))
  15168. {
  15169. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15170. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15171. isSuccess = ConfigurationStatus_Accepted;
  15172. }
  15173. else
  15174. {
  15175. isSuccess = ConfigurationStatus_Rejected;
  15176. }
  15177. }
  15178. }
  15179. else
  15180. {
  15181. isSuccess = ConfigurationStatus_Rejected;
  15182. }
  15183. }
  15184. if(strcmp(key, "MinimumStatusDuration") == 0)
  15185. {
  15186. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15187. {
  15188. check_ascii = value[0];
  15189. if( (check_ascii < 48) || (check_ascii > 57) )
  15190. {
  15191. isSuccess = ConfigurationStatus_Rejected;
  15192. }
  15193. else
  15194. {
  15195. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15196. {
  15197. isSuccess = ConfigurationStatus_Rejected;
  15198. }
  15199. else
  15200. {
  15201. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15203. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15204. isSuccess = ConfigurationStatus_Accepted;
  15205. }
  15206. }
  15207. }
  15208. else
  15209. {
  15210. isSuccess = ConfigurationStatus_Rejected;
  15211. }
  15212. }
  15213. if(strcmp(key, "NumberOfConnectors") == 0)
  15214. {
  15215. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15216. {
  15217. check_ascii = value[0];
  15218. if( (check_ascii < 48) || (check_ascii > 57) )
  15219. {
  15220. isSuccess = ConfigurationStatus_Rejected;
  15221. }
  15222. else
  15223. {
  15224. //Charger.ResetRetries = Integer.parseInt(value);
  15225. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15226. isSuccess = ConfigurationStatus_Accepted;
  15227. }
  15228. }
  15229. else
  15230. {
  15231. isSuccess = ConfigurationStatus_Rejected;
  15232. }
  15233. }
  15234. if(strcmp(key, "ResetRetries") == 0)
  15235. {
  15236. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15237. {
  15238. check_ascii = value[0];
  15239. if( (check_ascii < 48) || (check_ascii > 57) )
  15240. {
  15241. isSuccess = ConfigurationStatus_Rejected;
  15242. }
  15243. else
  15244. {
  15245. //Charger.ResetRetries = Integer.parseInt(value);
  15246. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15247. isSuccess = ConfigurationStatus_Accepted;
  15248. }
  15249. }
  15250. else
  15251. {
  15252. isSuccess = ConfigurationStatus_Rejected;
  15253. }
  15254. }
  15255. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15256. {
  15257. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15258. {
  15259. strcpy(str, (const char*)value);
  15260. for(int i = 0; str[i]; i++)
  15261. {
  15262. str[i] = tolower(str[i]);
  15263. }
  15264. if(strcmp(str, "notapplicable")== 0)
  15265. {
  15266. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15267. isSuccess = ConfigurationStatus_Accepted;
  15268. }
  15269. else if(strcmp(str, "unknown")== 0)
  15270. {
  15271. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15272. isSuccess = ConfigurationStatus_Accepted;
  15273. }
  15274. else if(strcmp(str, "rst")== 0)
  15275. {
  15276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15277. isSuccess = ConfigurationStatus_Accepted;
  15278. }
  15279. else if(strcmp(str, "rts")== 0)
  15280. {
  15281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15282. isSuccess = ConfigurationStatus_Accepted;
  15283. }
  15284. else if(strcmp(str, "srt")== 0)
  15285. {
  15286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15287. isSuccess = ConfigurationStatus_Accepted;
  15288. }
  15289. else if(strcmp(str, "str")== 0)
  15290. {
  15291. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15292. isSuccess = ConfigurationStatus_Accepted;
  15293. }
  15294. else if(strcmp(str, "trs")== 0)
  15295. {
  15296. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15297. isSuccess = ConfigurationStatus_Accepted;
  15298. }
  15299. else if(strcmp(str, "tsr")== 0)
  15300. {
  15301. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15302. isSuccess = ConfigurationStatus_Accepted;
  15303. }
  15304. else
  15305. {
  15306. isSuccess = ConfigurationStatus_Rejected;
  15307. }
  15308. }
  15309. else
  15310. {
  15311. isSuccess = ConfigurationStatus_Rejected;
  15312. }
  15313. }
  15314. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15315. {
  15316. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15317. {
  15318. check_ascii = value[0];
  15319. if( (check_ascii < 48) || (check_ascii > 57) )
  15320. {
  15321. isSuccess = ConfigurationStatus_Rejected;
  15322. }
  15323. else
  15324. {
  15325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15326. isSuccess = ConfigurationStatus_Accepted;
  15327. }
  15328. }
  15329. else
  15330. {
  15331. isSuccess = ConfigurationStatus_Rejected;
  15332. }
  15333. }
  15334. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15335. {
  15336. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15337. {
  15338. strcpy(str, (const char*)value);
  15339. for(int i = 0; str[i]; i++)
  15340. {
  15341. str[i] = tolower(str[i]);
  15342. }
  15343. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15345. isSuccess = ConfigurationStatus_Accepted;
  15346. }
  15347. else
  15348. {
  15349. isSuccess = ConfigurationStatus_Rejected;
  15350. }
  15351. }
  15352. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15353. {
  15354. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15355. {
  15356. strcpy(str, (const char*)value);
  15357. for(int i = 0; str[i]; i++)
  15358. {
  15359. str[i] = tolower(str[i]);
  15360. }
  15361. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15362. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15363. isSuccess = ConfigurationStatus_Accepted;
  15364. }
  15365. else
  15366. {
  15367. isSuccess = ConfigurationStatus_Rejected;
  15368. }
  15369. }
  15370. if(strcmp(key, "StopTxnAlignedData") == 0)
  15371. {
  15372. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15373. {
  15374. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15375. isSuccess = ConfigurationStatus_Accepted;
  15376. }
  15377. else
  15378. {
  15379. isSuccess = ConfigurationStatus_Rejected;
  15380. }
  15381. }
  15382. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15383. {
  15384. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15385. {
  15386. check_ascii = value[0];
  15387. if( (check_ascii < 48) || (check_ascii > 57) )
  15388. {
  15389. isSuccess = ConfigurationStatus_Rejected;
  15390. }
  15391. else
  15392. {
  15393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15394. isSuccess = ConfigurationStatus_Accepted;
  15395. }
  15396. }
  15397. else
  15398. {
  15399. isSuccess = ConfigurationStatus_Rejected;
  15400. }
  15401. }
  15402. if(strcmp(key, "StopTxnSampledData") == 0)
  15403. {
  15404. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15405. {
  15406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15407. isSuccess = ConfigurationStatus_Accepted;
  15408. }
  15409. else
  15410. {
  15411. isSuccess = ConfigurationStatus_Rejected;
  15412. }
  15413. }
  15414. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15415. {
  15416. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15417. {
  15418. check_ascii = value[0];
  15419. if( (check_ascii < 48) || (check_ascii > 57) )
  15420. {
  15421. isSuccess = ConfigurationStatus_Rejected;
  15422. }
  15423. else
  15424. {
  15425. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15426. isSuccess = ConfigurationStatus_Accepted;
  15427. }
  15428. }
  15429. else
  15430. {
  15431. isSuccess = ConfigurationStatus_Rejected;
  15432. }
  15433. }
  15434. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15435. {
  15436. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15437. {
  15438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15439. isSuccess = ConfigurationStatus_Accepted;
  15440. }
  15441. else
  15442. {
  15443. isSuccess = ConfigurationStatus_Rejected;
  15444. }
  15445. }
  15446. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15447. {
  15448. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15449. {
  15450. check_ascii = value[0];
  15451. if( (check_ascii < 48) || (check_ascii > 57) )
  15452. {
  15453. isSuccess = ConfigurationStatus_Rejected;
  15454. }
  15455. else
  15456. {
  15457. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15458. isSuccess = ConfigurationStatus_Accepted;
  15459. }
  15460. }
  15461. else
  15462. {
  15463. isSuccess = ConfigurationStatus_Rejected;
  15464. }
  15465. }
  15466. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15467. {
  15468. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15469. {
  15470. check_ascii = value[0];
  15471. if( (check_ascii < 48) || (check_ascii > 57) )
  15472. {
  15473. isSuccess = ConfigurationStatus_Rejected;
  15474. }
  15475. else
  15476. {
  15477. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15479. TransactionMessageAttemptsValue = atoi(value);
  15480. isSuccess = ConfigurationStatus_Accepted;
  15481. }
  15482. }
  15483. else
  15484. {
  15485. isSuccess = ConfigurationStatus_Rejected;
  15486. }
  15487. }
  15488. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15489. {
  15490. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15491. {
  15492. check_ascii = value[0];
  15493. if( (check_ascii < 48) || (check_ascii > 57) )
  15494. {
  15495. isSuccess = ConfigurationStatus_Rejected;
  15496. }
  15497. else
  15498. {
  15499. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15501. TransactionMessageRetryIntervalValue = atoi(value);
  15502. isSuccess = ConfigurationStatus_Accepted;
  15503. }
  15504. }
  15505. else
  15506. {
  15507. isSuccess = ConfigurationStatus_Rejected;
  15508. }
  15509. }
  15510. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15511. {
  15512. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15513. {
  15514. strcpy(str, (const char*)value);
  15515. for(int i = 0; str[i]; i++)
  15516. {
  15517. str[i] = tolower(str[i]);
  15518. }
  15519. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15521. isSuccess = ConfigurationStatus_Accepted;
  15522. }
  15523. else
  15524. {
  15525. isSuccess = ConfigurationStatus_Rejected;
  15526. }
  15527. }
  15528. if(strcmp(key, "WebSocketPingInterval") == 0)
  15529. {
  15530. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15531. {
  15532. check_ascii = value[0];
  15533. if( (check_ascii < 48) || (check_ascii > 57) )
  15534. {
  15535. isSuccess = ConfigurationStatus_Rejected;
  15536. }
  15537. else
  15538. {
  15539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15540. isSuccess = ConfigurationStatus_Accepted;
  15541. if((atoi(value) == 0) || (atoi(value) >= 10))
  15542. {
  15543. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15544. isSuccess = ConfigurationStatus_Accepted;
  15545. }
  15546. else
  15547. isSuccess = ConfigurationStatus_Rejected;
  15548. }
  15549. }
  15550. else
  15551. {
  15552. isSuccess = ConfigurationStatus_Rejected;
  15553. }
  15554. }
  15555. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15556. {
  15557. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15558. {
  15559. strcpy(str, (const char*)value);
  15560. for(int i = 0; str[i]; i++)
  15561. {
  15562. str[i] = tolower(str[i]);
  15563. }
  15564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15565. isSuccess = ConfigurationStatus_Accepted;
  15566. }
  15567. else
  15568. {
  15569. isSuccess = ConfigurationStatus_Rejected;
  15570. }
  15571. }
  15572. if(strcmp(key, "AuthorizationKey") == 0)
  15573. {
  15574. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15575. {
  15576. strcpy(str, (const char*)value);
  15577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15578. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15579. isSuccess = ConfigurationStatus_Accepted;
  15580. }
  15581. else
  15582. {
  15583. isSuccess = ConfigurationStatus_Rejected;
  15584. }
  15585. }
  15586. if(strcmp(key, "SecurityProfile") == 0)
  15587. {
  15588. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15589. {
  15590. check_ascii = value[0];
  15591. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15592. {
  15593. isSuccess = ConfigurationStatus_Rejected;
  15594. }
  15595. else if(check_ascii == 0x33)
  15596. {
  15597. isSuccess = NotSupported;
  15598. }
  15599. else
  15600. {
  15601. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15602. {
  15603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15604. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15605. isSuccess = ConfigurationStatus_Accepted;
  15606. }
  15607. else
  15608. isSuccess = ConfigurationStatus_Rejected;
  15609. }
  15610. }
  15611. else
  15612. {
  15613. isSuccess = ConfigurationStatus_Rejected;
  15614. }
  15615. }
  15616. if(strcmp(key, "DefaultPrice") == 0)
  15617. {
  15618. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15619. {
  15620. strcpy(str, (const char*)value);
  15621. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15622. isSuccess = ConfigurationStatus_Accepted;
  15623. }
  15624. else
  15625. {
  15626. isSuccess = ConfigurationStatus_Rejected;
  15627. }
  15628. }
  15629. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15630. {
  15631. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15632. {
  15633. strcpy(str, (const char*)value);
  15634. for(int i = 0; str[i]; i++)
  15635. {
  15636. str[i] = tolower(str[i]);
  15637. }
  15638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15639. isSuccess = ConfigurationStatus_Accepted;
  15640. }
  15641. else
  15642. {
  15643. isSuccess = ConfigurationStatus_Rejected;
  15644. }
  15645. }
  15646. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15647. {
  15648. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15649. {
  15650. strcpy(str, (const char*)value);
  15651. for(int i = 0; str[i]; i++)
  15652. {
  15653. str[i] = tolower(str[i]);
  15654. }
  15655. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15656. isSuccess = ConfigurationStatus_Accepted;
  15657. }
  15658. else
  15659. {
  15660. isSuccess = ConfigurationStatus_Rejected;
  15661. }
  15662. }
  15663. if(strcmp(key, "SystemUptimeSec") == 0)
  15664. {
  15665. isSuccess = NotSupported;
  15666. }
  15667. if(strcmp(key, "FreeVend") == 0)
  15668. {
  15669. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15670. {
  15671. strcpy(str, (const char*)value);
  15672. for(int i = 0; str[i]; i++)
  15673. {
  15674. str[i] = tolower(str[i]);
  15675. }
  15676. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15677. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15678. isSuccess = ConfigurationStatus_Accepted;
  15679. }
  15680. else
  15681. {
  15682. isSuccess = ConfigurationStatus_Rejected;
  15683. }
  15684. }
  15685. if(strcmp(key, "OcppServer") == 0)
  15686. {
  15687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15688. {
  15689. strcpy(str, (const char*)value);
  15690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  15691. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  15692. isSuccess = ConfigurationStatus_Accepted;
  15693. }
  15694. else
  15695. {
  15696. isSuccess = ConfigurationStatus_Rejected;
  15697. }
  15698. }
  15699. if(strcmp(key, "MaintainServer") == 0)
  15700. {
  15701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15702. {
  15703. strcpy(str, (const char*)value);
  15704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  15705. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  15706. isSuccess = ConfigurationStatus_Accepted;
  15707. }
  15708. else
  15709. {
  15710. isSuccess = ConfigurationStatus_Rejected;
  15711. }
  15712. }
  15713. #if 0
  15714. //For OCPP Test Case
  15715. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15716. {
  15717. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15718. {
  15719. strcpy(str, (const char*)value);
  15720. for(int i = 0; str[i]; i++)
  15721. {
  15722. str[i] = tolower(str[i]);
  15723. }
  15724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15725. isSuccess = ConfigurationStatus_Accepted;
  15726. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15727. }
  15728. else
  15729. {
  15730. isSuccess = ConfigurationStatus_Rejected;
  15731. }
  15732. }
  15733. #endif
  15734. #if 1
  15735. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15736. {
  15737. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15738. {
  15739. strcpy(str, (const char*)value);
  15740. for(int i = 0; str[i]; i++)
  15741. {
  15742. str[i] = tolower(str[i]);
  15743. }
  15744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15745. isSuccess = ConfigurationStatus_Accepted;
  15746. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15747. }
  15748. else
  15749. {
  15750. isSuccess = ConfigurationStatus_Rejected;
  15751. }
  15752. }
  15753. #endif
  15754. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15755. {
  15756. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15757. {
  15758. check_ascii = value[0];
  15759. if( (check_ascii < 48) || (check_ascii > 57) )
  15760. {
  15761. isSuccess = ConfigurationStatus_Rejected;
  15762. }
  15763. else
  15764. {
  15765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15766. isSuccess = ConfigurationStatus_Accepted;
  15767. }
  15768. }
  15769. else
  15770. {
  15771. isSuccess = ConfigurationStatus_Rejected;
  15772. }
  15773. }
  15774. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15775. {
  15776. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].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.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15786. isSuccess = ConfigurationStatus_Accepted;
  15787. }
  15788. }
  15789. else
  15790. {
  15791. isSuccess = ConfigurationStatus_Rejected;
  15792. }
  15793. }
  15794. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15795. {
  15796. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15797. {
  15798. strcpy(str, (const char*)value);
  15799. for(int i = 0; str[i]; i++)
  15800. {
  15801. str[i] = tolower(str[i]);
  15802. }
  15803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15804. isSuccess = ConfigurationStatus_Accepted;
  15805. }
  15806. else
  15807. {
  15808. isSuccess = ConfigurationStatus_Rejected;
  15809. }
  15810. }
  15811. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15812. {
  15813. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15814. {
  15815. check_ascii = value[0];
  15816. if( (check_ascii < 48) || (check_ascii > 57) )
  15817. {
  15818. isSuccess = ConfigurationStatus_Rejected;
  15819. }
  15820. else
  15821. {
  15822. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15823. isSuccess = ConfigurationStatus_Accepted;
  15824. }
  15825. }
  15826. else
  15827. {
  15828. isSuccess = ConfigurationStatus_Rejected;
  15829. }
  15830. }
  15831. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15832. {
  15833. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15834. {
  15835. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15836. isSuccess = ConfigurationStatus_Accepted;
  15837. }
  15838. else
  15839. {
  15840. isSuccess = ConfigurationStatus_Rejected;
  15841. }
  15842. }
  15843. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15844. {
  15845. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15846. {
  15847. check_ascii = value[0];
  15848. if( (check_ascii < 48) || (check_ascii > 57) )
  15849. {
  15850. isSuccess = ConfigurationStatus_Rejected;
  15851. }
  15852. else
  15853. {
  15854. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15855. isSuccess = ConfigurationStatus_Accepted;
  15856. }
  15857. }
  15858. else
  15859. {
  15860. isSuccess = ConfigurationStatus_Rejected;
  15861. }
  15862. }
  15863. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15864. {
  15865. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15866. {
  15867. strcpy(str, (const char*)value);
  15868. for(int i = 0; str[i]; i++)
  15869. {
  15870. str[i] = tolower(str[i]);
  15871. }
  15872. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15873. isSuccess = ConfigurationStatus_Accepted;
  15874. }
  15875. else
  15876. {
  15877. isSuccess = ConfigurationStatus_Rejected;
  15878. }
  15879. }
  15880. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15881. {
  15882. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15883. {
  15884. check_ascii = value[0];
  15885. if( (check_ascii < 48) || (check_ascii > 57) )
  15886. {
  15887. isSuccess = ConfigurationStatus_Rejected;
  15888. }
  15889. else
  15890. {
  15891. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15892. isSuccess = ConfigurationStatus_Accepted;
  15893. }
  15894. }
  15895. else
  15896. {
  15897. isSuccess = ConfigurationStatus_Rejected;
  15898. }
  15899. }
  15900. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15901. return isSuccess;
  15902. }
  15903. int TransactionMessageAttemptsGet(void)
  15904. {
  15905. return TransactionMessageAttemptsValue;
  15906. }
  15907. int FirstHeartBeatResponse(void)
  15908. {
  15909. return FirstHeartBeat;
  15910. }
  15911. int TransactionMessageRetryIntervalGet(void)
  15912. {
  15913. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15914. }
  15915. int ReadHttpStatus(int sock)
  15916. {
  15917. //char c;
  15918. char buff[1024]="",*ptr=buff+1;
  15919. int bytes_received, status;
  15920. DEBUG_INFO("Begin Response ..\n");
  15921. while((bytes_received = recv(sock, ptr, 1, 0))){
  15922. if(bytes_received==-1){
  15923. perror("ReadHttpStatus");
  15924. exit(1);
  15925. }
  15926. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15927. ptr++;
  15928. }
  15929. *ptr=0;
  15930. ptr=buff+1;
  15931. sscanf(ptr,"%*s %d ", &status);
  15932. DEBUG_INFO("%s\n",ptr);
  15933. DEBUG_INFO("status=%d\n",status);
  15934. DEBUG_INFO("End Response ..\n");
  15935. return (bytes_received>0)?status:0;
  15936. }
  15937. //the only filed that it parsed is 'Content-Length'
  15938. int ParseHeader(int sock)
  15939. {
  15940. //char c;
  15941. char buff[1024]="",*ptr=buff+4;
  15942. int bytes_received;
  15943. DEBUG_INFO("Begin HEADER ..\n");
  15944. while((bytes_received = recv(sock, ptr, 1, 0))){
  15945. if(bytes_received==-1){
  15946. perror("Parse Header");
  15947. exit(1);
  15948. }
  15949. if(
  15950. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15951. (ptr[-1]=='\r') && (*ptr=='\n' )
  15952. ) break;
  15953. ptr++;
  15954. }
  15955. *ptr=0;
  15956. ptr=buff+4;
  15957. //printf("%s",ptr);
  15958. if(bytes_received){
  15959. ptr=strstr(ptr,"Content-Length:");
  15960. if(ptr){
  15961. sscanf(ptr,"%*s %d",&bytes_received);
  15962. }else
  15963. bytes_received=-1; //unknown size
  15964. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15965. }
  15966. DEBUG_INFO("End HEADER ..\n");
  15967. return bytes_received ;
  15968. }
  15969. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15970. {
  15971. int result = TRUE;
  15972. char rmFileCmd[100]={0};
  15973. char FilePath[100]={0};
  15974. char ftpbuf[200];
  15975. int systemresult;
  15976. sprintf(FilePath,"/mnt/%s",filename);
  15977. system("ping 8.8.8.8 &");
  15978. if((access(FilePath,F_OK))!=-1)
  15979. {
  15980. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15981. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15982. system(rmFileCmd);
  15983. }
  15984. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15985. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15986. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15987. systemresult = system(ftpbuf);
  15988. if(systemresult != 0)
  15989. {
  15990. DEBUG_INFO("http DownLoad error!\n");
  15991. result = FALSE;
  15992. }
  15993. system("pkill ping");
  15994. return result;
  15995. }
  15996. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15997. {
  15998. int result = TRUE;
  15999. char rmFileCmd[100]={0};
  16000. char FilePath[100]={0};
  16001. char ftpbuf[200];
  16002. int systemresult;
  16003. sprintf(FilePath,"/mnt/%s",filename);
  16004. system("ping 8.8.8.8 &");
  16005. if((access(FilePath,F_OK))!=-1)
  16006. {
  16007. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16008. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16009. system(rmFileCmd);
  16010. }
  16011. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16012. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16013. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16014. systemresult = system(ftpbuf);
  16015. if(systemresult != 0)
  16016. {
  16017. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16018. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16019. systemresult = system(ftpbuf);
  16020. if(systemresult != 0)
  16021. {
  16022. DEBUG_WARN("wget error!\n");
  16023. result = FALSE;
  16024. }
  16025. }
  16026. system("pkill ping");
  16027. return result;
  16028. }
  16029. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16030. {
  16031. char rmFileCmd[100]={0};
  16032. char FilePath[100]={0};
  16033. char buf[512];
  16034. int systemresult = 0;
  16035. //DEBUG_INFO("filename=%s\n",filename);
  16036. //DEBUG_INFO("url=%s\n",url);
  16037. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16038. if((access(FilePath,F_OK))!=-1)
  16039. {
  16040. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16041. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16042. system(rmFileCmd);
  16043. }
  16044. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16045. if(fp == NULL)
  16046. {
  16047. DEBUG_INFO("log is NULL\n");
  16048. return FALSE;
  16049. }
  16050. else
  16051. {
  16052. fprintf(fp, "%s\n", url);
  16053. fprintf(fp, "%s\n", filename);
  16054. fclose(fp);
  16055. }
  16056. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16057. if(phpFP == NULL)
  16058. {
  16059. DEBUG_INFO("PHP upload fail.\n");
  16060. return FALSE;
  16061. }
  16062. else
  16063. {
  16064. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16065. {
  16066. if(strstr(buf, "result") != NULL)
  16067. {
  16068. sscanf(buf, "result: %d", &systemresult);
  16069. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16070. }
  16071. }
  16072. pclose(phpFP);
  16073. }
  16074. if(systemresult != 1)
  16075. {
  16076. DEBUG_INFO("HTTP upload error!\n");
  16077. return FALSE;
  16078. }
  16079. return TRUE;
  16080. }
  16081. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16082. {
  16083. int result = FALSE;
  16084. char ftpbuf[200];
  16085. int systemresult;
  16086. /*
  16087. // Domaind name transfer to IP address
  16088. struct hostent* server;
  16089. char *IPbuffer;
  16090. server = gethostbyname(location);
  16091. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16092. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16093. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16094. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16095. systemresult = system(ftpbuf);
  16096. if(systemresult != 0)
  16097. {
  16098. DEBUG_INFO("ftpput error!\n");
  16099. }
  16100. else
  16101. {
  16102. result = TRUE;
  16103. DEBUG_INFO("ftpput OK!\n");
  16104. }
  16105. return result;
  16106. }
  16107. int GetOcppServerURL()
  16108. {
  16109. int result = FALSE;
  16110. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16111. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16112. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16113. struct yuarel url;
  16114. char urlStr[512];
  16115. // OCPPPH only
  16116. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16117. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16118. {
  16119. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16120. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16121. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16122. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16123. if(yuarel_parse(&url, urlStr) != -1)
  16124. {
  16125. sprintf(OcppProtocol, "%s", url.scheme);
  16126. sprintf(OcppHost, "%s", url.host);
  16127. if(url.path == NULL)
  16128. OcppTempPath[0] = '\0';
  16129. else
  16130. sprintf(OcppTempPath, "%s", url.path);
  16131. if(url.port == 0)
  16132. {
  16133. if(strcmp(OcppProtocol, "wss") == 0)
  16134. OcppPort = 443;
  16135. else
  16136. OcppPort = 80;
  16137. }
  16138. else
  16139. OcppPort = url.port;
  16140. result = TRUE;
  16141. }
  16142. }
  16143. else
  16144. {
  16145. strcpy(OcppHost,"");
  16146. }
  16147. return result;
  16148. }
  16149. int GetOcppPath()
  16150. {
  16151. int result = FALSE;
  16152. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16153. {
  16154. if(OcppTempPath == NULL)
  16155. {
  16156. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16157. }
  16158. else
  16159. {
  16160. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16161. }
  16162. result = TRUE;
  16163. goto End;
  16164. }
  16165. else
  16166. {
  16167. strcpy(OcppPath,"");
  16168. }
  16169. End:
  16170. return result;
  16171. }
  16172. int GetOcppPort()
  16173. {
  16174. return OcppPort;
  16175. }
  16176. int GetOcppConnStatus(void)
  16177. {
  16178. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16179. }
  16180. void SetOcppConnStatus(uint8_t status)
  16181. {
  16182. ShmOCPP16DataPH->OcppConnStatus = status;
  16183. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16184. }
  16185. int GetHeartBeatWithNOResponse(void)
  16186. {
  16187. return HeartBeatWithNOResponse;
  16188. }
  16189. void SetHeartBeatWithNOResponse(void)
  16190. {
  16191. HeartBeatWithNOResponse = 0;
  16192. }
  16193. void GetStartTransactionIdTag(int gun_index)
  16194. {
  16195. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16196. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16197. }
  16198. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16199. {
  16200. char ch;
  16201. FILE *fptr1;
  16202. int temptransactionId;
  16203. char str[100]={0};
  16204. temptransactionId = 0;
  16205. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16206. {
  16207. DEBUG_INFO("IdTag is empty.\n");
  16208. return temptransactionId;
  16209. }
  16210. /*------ Read the file ----------------*/
  16211. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16212. if (!fptr1)
  16213. {
  16214. DEBUG_INFO("QueueTransactionId file open error.\n");
  16215. //printf(" File not found or unable to open the input file!!\n");
  16216. return temptransactionId;
  16217. }
  16218. ch=fgetc(fptr1);
  16219. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16220. rewind(fptr1);
  16221. if(ch!=EOF)
  16222. {
  16223. // printf("%c",ch);
  16224. while (fgets(str, 100, fptr1) != NULL)
  16225. {
  16226. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16227. if(str[0]=='\0')
  16228. {
  16229. break;
  16230. }
  16231. char *revbuf[8] = {0}; // Variable store string split
  16232. int num = 0;// Quantity after string split
  16233. DEBUG_INFO("Transaction queue data= %s\n", str);
  16234. splitstring(str,",",revbuf,&num); // String split
  16235. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16236. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16237. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16238. DEBUG_INFO("------------------------------\n");
  16239. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16240. {
  16241. if(isStopTransaction)
  16242. {
  16243. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16244. {
  16245. temptransactionId = atoi(revbuf[2]);
  16246. //break;
  16247. }
  16248. }
  16249. else
  16250. {
  16251. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16252. {
  16253. temptransactionId = atoi(revbuf[2]);
  16254. //break;
  16255. }
  16256. }
  16257. }
  16258. }
  16259. }
  16260. else
  16261. DEBUG_INFO("EOF\n");
  16262. fclose(fptr1);
  16263. /*------- End of reading ---------------*/
  16264. return temptransactionId;
  16265. }
  16266. void SetTransactionIdZero(int transactionId)
  16267. {
  16268. char ch;
  16269. FILE *fptr1, *fptr2;
  16270. int temptransactionId = 0;
  16271. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16272. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16273. if (!fptr1)
  16274. {
  16275. //printf(" File not found or unable to open the input file!!\n");
  16276. return ;
  16277. }
  16278. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16279. if (!fptr2)
  16280. {
  16281. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16282. fclose(fptr1);
  16283. return ;
  16284. }
  16285. ch=fgetc(fptr1);
  16286. rewind(fptr1);
  16287. if(ch!=EOF)
  16288. {
  16289. // copy all contents to the temporary file except the specific line
  16290. while (fgets(str, 100, fptr1) != NULL)
  16291. {
  16292. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16293. if(str[0]=='\0')
  16294. {
  16295. break;
  16296. }
  16297. char *revbuf[8] = {0};
  16298. int num = 0;
  16299. strcpy(strtemp, str);
  16300. splitstring(str,",",revbuf,&num);
  16301. if(revbuf[2][0] != '\0')
  16302. {
  16303. temptransactionId = atoi(revbuf[2]);
  16304. if(transactionId != temptransactionId)
  16305. {
  16306. fprintf(fptr2, "%s\n", strtemp);
  16307. }
  16308. }
  16309. }
  16310. }
  16311. fclose(fptr1);
  16312. fclose(fptr2);
  16313. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16314. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16315. /*------ Read the file ----------------*/
  16316. }
  16317. int InternetDisconnect(void)
  16318. {
  16319. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16320. }
  16321. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16322. void storeTempStopTransaction(int gun_index)
  16323. {
  16324. char guid[37]={0};
  16325. int tempIndex = 0;
  16326. char TempStopTransaction[256];
  16327. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16328. DEBUG_INFO("storeTempStopTransaction...\n");
  16329. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16330. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16331. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16332. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16333. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16334. {
  16335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16336. {
  16337. tempIndex = ((gun_index==2) ? 1: 0);
  16338. }
  16339. else
  16340. {
  16341. tempIndex = gun_index;
  16342. }
  16343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16344. {
  16345. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16346. {
  16347. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16348. }
  16349. }// END OF CHAdeMO_QUANTITY
  16350. }
  16351. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16352. {
  16353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16354. {
  16355. tempIndex = ((gun_index==2) ? 1: 0);
  16356. }
  16357. else
  16358. {
  16359. tempIndex = gun_index;
  16360. }
  16361. for (int index = 0; index < CCS_QUANTITY; index++)
  16362. {
  16363. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16364. {
  16365. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16366. }
  16367. }// END OF CCS_QUANTITY
  16368. }
  16369. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16370. {
  16371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16372. {
  16373. tempIndex = ((gun_index==2) ? 1: 0);
  16374. }
  16375. else
  16376. {
  16377. tempIndex = gun_index;
  16378. }
  16379. for (int index = 0; index < GB_QUANTITY; index++)
  16380. {
  16381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16382. {
  16383. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16384. }
  16385. }// END OF GB_QUANTITY
  16386. }
  16387. else if(gunType[gun_index] == GUN_TYPE_DO)
  16388. {
  16389. tempIndex = gun_index;
  16390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16391. {
  16392. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16393. {
  16394. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16395. }
  16396. }
  16397. }
  16398. else
  16399. {
  16400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16401. {
  16402. tempIndex = 2;
  16403. }
  16404. else
  16405. {
  16406. tempIndex = gun_index;
  16407. }
  16408. for (int index = 0; index < AC_QUANTITY; index++)
  16409. {
  16410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16411. {
  16412. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16413. }
  16414. }// END OF AC_QUANTITY
  16415. }
  16416. //Stop Transaction Time
  16417. struct timeval tmnow;
  16418. struct tm *tm;
  16419. char buf[28];//, usec_buf[6];
  16420. gettimeofday(&tmnow, NULL);
  16421. time_t t;
  16422. t = time(NULL);
  16423. /*UTC time and date*/
  16424. tm = gmtime(&t);
  16425. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16426. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16427. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16429. random_uuid(guid);
  16430. /***********************************transactionData******************************************************/
  16431. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16432. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16433. //=================================
  16434. //1. Transaction_Begin
  16435. //=================================
  16436. //============================== Energy.Active.Import.Interval ===========================================
  16437. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16438. {
  16439. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16440. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16442. 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*/]);
  16443. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16444. 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))
  16445. {
  16446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16447. }
  16448. else
  16449. {
  16450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16451. }
  16452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16454. }
  16455. //=================================
  16456. //2. Transaction_End
  16457. //=================================
  16458. //2.1====================================== Current.Import L1 ==============================================
  16459. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16460. {
  16461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16463. {
  16464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16465. {
  16466. tempIndex = ((gun_index==2) ? 1: 0);
  16467. }
  16468. else
  16469. {
  16470. tempIndex = gun_index;
  16471. }
  16472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16473. {
  16474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16475. {
  16476. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16477. }
  16478. }// End of for CHAdeMO_QUANTITY
  16479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16480. }
  16481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16482. {
  16483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16484. {
  16485. tempIndex = ((gun_index==2) ? 1: 0);
  16486. }
  16487. else
  16488. {
  16489. tempIndex = gun_index;
  16490. }
  16491. for (int index = 0; index < CCS_QUANTITY; index++)
  16492. {
  16493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16494. {
  16495. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16496. }
  16497. }// End of for CCS_QUANTITY
  16498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16499. }
  16500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16501. {
  16502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16503. {
  16504. tempIndex = ((gun_index==2) ? 1: 0);
  16505. }
  16506. else
  16507. {
  16508. tempIndex = gun_index;
  16509. }
  16510. for (int index = 0; index < GB_QUANTITY; index++)
  16511. {
  16512. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16513. {
  16514. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16515. }
  16516. }// End of for GB_QUANTITY
  16517. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16518. }
  16519. else if(gunType[gun_index] == GUN_TYPE_DO)
  16520. {
  16521. tempIndex = gun_index;
  16522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16523. {
  16524. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16525. {
  16526. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16527. }
  16528. }
  16529. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16530. }
  16531. else
  16532. {
  16533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16534. {
  16535. tempIndex = 2;
  16536. }
  16537. else
  16538. {
  16539. tempIndex = gun_index;
  16540. }
  16541. for (int index = 0; index < AC_QUANTITY; index++)
  16542. {
  16543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16544. {
  16545. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16546. }
  16547. }// End of for AC_QUANTITY
  16548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16549. }
  16550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16551. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16553. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16555. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16556. }
  16557. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16558. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16559. {
  16560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16561. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16562. {
  16563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16564. {
  16565. tempIndex = ((gun_index==2) ? 1: 0);
  16566. }
  16567. else
  16568. {
  16569. tempIndex = gun_index;
  16570. }
  16571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16572. {
  16573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16574. {
  16575. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16576. }
  16577. }// END OF CHAdeMO_QUANTITY
  16578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16579. }
  16580. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16581. {
  16582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16583. {
  16584. tempIndex = ((gun_index==2) ? 1: 0);
  16585. }
  16586. else
  16587. {
  16588. tempIndex = gun_index;
  16589. }
  16590. for (int index = 0; index < CCS_QUANTITY; index++)
  16591. {
  16592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16593. {
  16594. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16595. }
  16596. }// END OF CCS_QUANTITY
  16597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16598. }
  16599. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16600. {
  16601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16602. {
  16603. tempIndex = ((gun_index==2) ? 1: 0);
  16604. }
  16605. else
  16606. {
  16607. tempIndex = gun_index;
  16608. }
  16609. for (int index = 0; index < GB_QUANTITY; index++)
  16610. {
  16611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16612. {
  16613. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16614. }
  16615. }// END OF GB_QUANTITY
  16616. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16617. }
  16618. else if(gunType[gun_index] == GUN_TYPE_DO)
  16619. {
  16620. tempIndex = gun_index;
  16621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16622. {
  16623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16624. {
  16625. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16626. }
  16627. }
  16628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16629. }
  16630. else
  16631. {
  16632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16633. {
  16634. tempIndex = 2;
  16635. }
  16636. else
  16637. {
  16638. tempIndex = gun_index;
  16639. }
  16640. for (int index = 0; index < AC_QUANTITY; index++)
  16641. {
  16642. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16643. {
  16644. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16645. }
  16646. }// END OF AC_QUANTITY
  16647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16648. }
  16649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16652. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16655. }
  16656. //2.3====================================== Power.Active.Import =========================================
  16657. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16658. {
  16659. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16660. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16661. {
  16662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16663. {
  16664. tempIndex = ((gun_index==2) ? 1: 0);
  16665. }
  16666. else
  16667. {
  16668. tempIndex = gun_index;
  16669. }
  16670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16671. {
  16672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16673. {
  16674. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16675. }
  16676. } // End for CHAdeMO_QUANTITY
  16677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16678. }
  16679. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16680. {
  16681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16682. {
  16683. tempIndex = ((gun_index==2) ? 1: 0);
  16684. }
  16685. else
  16686. {
  16687. tempIndex = gun_index;
  16688. }
  16689. for (int index = 0; index < CCS_QUANTITY; index++)
  16690. {
  16691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16692. {
  16693. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16694. }
  16695. } // END for CCS_QUANTITY
  16696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16697. }
  16698. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16699. {
  16700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16701. {
  16702. tempIndex = ((gun_index==2) ? 1: 0);
  16703. }
  16704. else
  16705. {
  16706. tempIndex = gun_index;
  16707. }
  16708. for (int index = 0; index < GB_QUANTITY; index++)
  16709. {
  16710. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16711. {
  16712. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16713. }
  16714. }// END for GB_QUANTITY
  16715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16716. }
  16717. else if(gunType[gun_index] == GUN_TYPE_DO)
  16718. {
  16719. tempIndex = gun_index;
  16720. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16721. {
  16722. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16723. {
  16724. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16725. }
  16726. }
  16727. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16728. }
  16729. else
  16730. {
  16731. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16732. {
  16733. tempIndex = 2;
  16734. }
  16735. else
  16736. {
  16737. tempIndex = gun_index;
  16738. }
  16739. for (int index = 0; index < AC_QUANTITY; index++)
  16740. {
  16741. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16742. {
  16743. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16744. }
  16745. } // END for AC_QUANTITY
  16746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16747. }
  16748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16751. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16754. }
  16755. //2.4====================================== Voltage L1 ====================================================
  16756. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16757. {
  16758. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16759. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16760. {
  16761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16762. {
  16763. tempIndex = ((gun_index==2) ? 1: 0);
  16764. }
  16765. else
  16766. {
  16767. tempIndex = gun_index;
  16768. }
  16769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16770. {
  16771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16772. {
  16773. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16774. }
  16775. } // END OF FOR CHAdeMO_QUANTITY
  16776. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16777. }
  16778. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16779. {
  16780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16781. {
  16782. tempIndex = ((gun_index==2) ? 1: 0);
  16783. }
  16784. else
  16785. {
  16786. tempIndex = gun_index;
  16787. }
  16788. for (int index = 0; index < CCS_QUANTITY; index++)
  16789. {
  16790. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16791. {
  16792. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16793. }
  16794. } // END OF FOR CCS_QUANTITY
  16795. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16796. }
  16797. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16798. {
  16799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16800. {
  16801. tempIndex = ((gun_index==2) ? 1: 0);
  16802. }
  16803. else
  16804. {
  16805. tempIndex = gun_index;
  16806. }
  16807. for (int index = 0; index < GB_QUANTITY; index++)
  16808. {
  16809. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16810. {
  16811. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16812. }
  16813. } // END OF FOR GB_QUANTITY
  16814. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16815. }
  16816. else if(gunType[gun_index] == GUN_TYPE_DO)
  16817. {
  16818. tempIndex = gun_index;
  16819. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16820. {
  16821. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16822. {
  16823. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16824. }
  16825. }
  16826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16827. }
  16828. else
  16829. {
  16830. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16831. {
  16832. tempIndex = 2;
  16833. }
  16834. else
  16835. {
  16836. tempIndex = gun_index;
  16837. }
  16838. for (int index = 0; index < AC_QUANTITY; index++)
  16839. {
  16840. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16841. {
  16842. 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
  16843. }
  16844. } // END OF FOR AC_QUANTITY
  16845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16846. }
  16847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16848. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16849. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16850. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16852. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16853. }
  16854. //2.5============================================== End SoC =========================================================
  16855. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16856. {
  16857. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16858. 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))
  16859. {
  16860. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16861. {
  16862. tempIndex = ((gun_index==2) ? 1: 0);
  16863. }
  16864. else
  16865. {
  16866. tempIndex = gun_index;
  16867. }
  16868. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16869. {
  16870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16871. {
  16872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16873. {
  16874. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16875. }
  16876. }
  16877. }
  16878. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16879. {
  16880. for (int index = 0; index < CCS_QUANTITY; index++)
  16881. {
  16882. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16883. {
  16884. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16885. }
  16886. }
  16887. }
  16888. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16889. {
  16890. for (int index = 0; index < GB_QUANTITY; index++)
  16891. {
  16892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16893. {
  16894. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16895. }
  16896. }
  16897. }
  16898. else if(gunType[gun_index] == GUN_TYPE_DO)
  16899. {
  16900. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16901. {
  16902. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16903. {
  16904. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16905. }
  16906. }
  16907. }
  16908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16909. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16911. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16912. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16913. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16914. } // END FOR DC CASE
  16915. }
  16916. //2.6====================================== Current.Import L2 ==============================================
  16917. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16918. {
  16919. // AC 3 phase L2 current
  16920. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16921. {
  16922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16923. {
  16924. tempIndex = 2;
  16925. }
  16926. else
  16927. {
  16928. tempIndex = gun_index;
  16929. }
  16930. for (int index = 0; index < AC_QUANTITY; index++)
  16931. {
  16932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16933. {
  16934. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16935. }
  16936. }// End of for AC_QUANTITY
  16937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16938. }
  16939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16944. }
  16945. //2.7====================================== Current.Import L3 ==============================================
  16946. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16947. {
  16948. // AC 3 phase L3 current
  16949. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16950. {
  16951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16952. {
  16953. tempIndex = 2;
  16954. }
  16955. else
  16956. {
  16957. tempIndex = gun_index;
  16958. }
  16959. for (int index = 0; index < AC_QUANTITY; index++)
  16960. {
  16961. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16962. {
  16963. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16964. }
  16965. }// End of for AC_QUANTITY
  16966. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16967. }
  16968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16973. }
  16974. //2.9====================================== Voltage L2 ====================================================
  16975. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16976. {
  16977. // AC 3 phase L2 volatge
  16978. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16979. {
  16980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16981. {
  16982. tempIndex = 2;
  16983. }
  16984. else
  16985. {
  16986. tempIndex = gun_index;
  16987. }
  16988. for (int index = 0; index < AC_QUANTITY; index++)
  16989. {
  16990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16991. {
  16992. 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
  16993. }
  16994. } // END OF FOR AC_QUANTITY
  16995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16996. }
  16997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17002. }
  17003. //2.10====================================== Voltage L3 ====================================================
  17004. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17005. {
  17006. // AC 3 phase L3 volatge
  17007. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17008. {
  17009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17010. {
  17011. tempIndex = 2;
  17012. }
  17013. else
  17014. {
  17015. tempIndex = gun_index;
  17016. }
  17017. for (int index = 0; index < AC_QUANTITY; index++)
  17018. {
  17019. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17020. {
  17021. 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
  17022. }
  17023. } // END OF FOR AC_QUANTITY
  17024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17025. }
  17026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17031. }
  17032. //====================== Start SoC ================================
  17033. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17034. {
  17035. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17036. 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))
  17037. {
  17038. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17039. {
  17040. tempIndex = ((gun_index==2) ? 1: 0);
  17041. }
  17042. else
  17043. {
  17044. tempIndex = gun_index;
  17045. }
  17046. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17047. {
  17048. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17049. {
  17050. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17051. {
  17052. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17053. }
  17054. }
  17055. }
  17056. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17057. {
  17058. for (int index = 0; index < CCS_QUANTITY; index++)
  17059. {
  17060. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17061. {
  17062. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17063. }
  17064. }
  17065. }
  17066. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17067. {
  17068. for (int index = 0; index < GB_QUANTITY; index++)
  17069. {
  17070. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17071. {
  17072. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17073. }
  17074. }
  17075. }
  17076. else if(gunType[gun_index] == GUN_TYPE_DO)
  17077. {
  17078. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17079. {
  17080. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17081. {
  17082. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17083. }
  17084. }
  17085. }
  17086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17087. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17090. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17092. } // END FOR DC CASE
  17093. }
  17094. //======================================== Message create ==============================================
  17095. json_object *StopTransaction = json_object_new_object();
  17096. json_object *transactionDatas = json_object_new_array();
  17097. json_object *sampledValues = json_object_new_array();
  17098. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17099. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17100. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17101. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17102. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17103. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17104. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17105. {
  17106. json_object *transactionData = json_object_new_object();
  17107. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17108. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17109. {
  17110. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17111. {
  17112. json_object *sampledValue = json_object_new_object();
  17113. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17114. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17115. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17116. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17117. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17118. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17119. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17120. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17121. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17122. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17123. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17124. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17125. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17126. json_object_array_add(sampledValues, sampledValue);
  17127. }
  17128. }
  17129. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17130. json_object_array_add(transactionDatas, transactionData);
  17131. }
  17132. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17133. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17134. ,MESSAGE_TYPE_CALL
  17135. ,guid
  17136. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17137. json_object_put(StopTransaction);
  17138. // Check File "TempStopTransaction" Exist
  17139. if((access(TempStopTransaction,F_OK))!=-1)
  17140. {
  17141. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17142. fclose(fopen(TempStopTransaction, "w"));
  17143. }
  17144. else
  17145. {
  17146. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17147. FILE *log = fopen(TempStopTransaction, "w+");
  17148. if(log == NULL)
  17149. {
  17150. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17151. return ;
  17152. }
  17153. else
  17154. {
  17155. fclose(log);
  17156. }
  17157. }
  17158. //Add TempStopTransaction | Update TempStopTransaction
  17159. // open file for writing
  17160. FILE *outfile;
  17161. outfile = fopen (TempStopTransaction, "a");
  17162. //DEBUG_INFO("data = %s\n", queuedata);
  17163. fputs(queuedata, outfile);
  17164. fputs("\n", outfile);
  17165. fclose (outfile);
  17166. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17167. }
  17168. void checkTempStopTransaction(int gun_index)
  17169. {
  17170. FILE *fptr1;
  17171. char ch;
  17172. char str[QUEUE_MESSAGE_LENGTH]={0};
  17173. char guid[37]={0};
  17174. char tempdata[65]={0};
  17175. char connectorStr[2]={0};
  17176. char TempStopTransaction[256];
  17177. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17178. fptr1 = fopen(TempStopTransaction, "r");
  17179. //TempStopTransaction格式: 槍號,StopTransaction封包
  17180. if (!fptr1)
  17181. {
  17182. //printf(" File not found or unable to open the input file!!\n");
  17183. return ;
  17184. }
  17185. ch=fgetc(fptr1);
  17186. //printf(" Now the content of the file %s is : \n",fname);
  17187. rewind(fptr1);
  17188. if(ch!=EOF)
  17189. {
  17190. // copy all contents to the temporary file except the specific line
  17191. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17192. {
  17193. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17194. if(str[0]=='\0')
  17195. {
  17196. break;
  17197. }
  17198. //TempStopTransaction格式: 槍號,StopTransaction封包
  17199. strncpy(connectorStr, str, 1);
  17200. if(atoi(connectorStr) != (gun_index+1))
  17201. {
  17202. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17203. fclose(fptr1);
  17204. return ;
  17205. }
  17206. //random_uuid(guid);
  17207. strncpy(guid, str+6, 36); //copy guid
  17208. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17209. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17210. {
  17211. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17212. }
  17213. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17214. OCPP_insert_transaction_msg(NO, str);
  17215. memset(str,0,ARRAY_SIZE(str));
  17216. }
  17217. }
  17218. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17219. fclose(fptr1);
  17220. remove(TempStopTransaction); // remove the original file
  17221. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17222. }
  17223. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17224. {
  17225. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17226. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17227. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17228. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17229. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17230. }
  17231. int GetWebSocketPingInterval(void)
  17232. {
  17233. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17234. }
  17235. int GetServerSign(void)
  17236. {
  17237. return server_sign;
  17238. }
  17239. uint8_t GetOcppSecurityProfile()
  17240. {
  17241. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17242. }
  17243. void GetOcppChargerBoxId(uint8_t *data)
  17244. {
  17245. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17246. }
  17247. void GetOcppSecurityPassword(uint8_t *data)
  17248. {
  17249. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17250. }
  17251. void SetOcppVersion(uint8_t *version)
  17252. {
  17253. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17254. DEBUG_INFO("ocpp version: %s\n", version);
  17255. if(strstr((char*)version, "ocpp1.6") != NULL)
  17256. {
  17257. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17258. }
  17259. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17260. {
  17261. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17262. system("pkill OcppBackend");
  17263. }
  17264. }
  17265. void SetServerSign(int value)
  17266. {
  17267. server_sign = value;
  17268. }
  17269. int GetBootNotificationInterval(void)
  17270. {
  17271. return BootNotificationInterval;
  17272. }
  17273. int GetInternetConn(void)
  17274. {
  17275. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17276. }
  17277. int GetBackendConnectionTimeout(void)
  17278. {
  17279. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17280. }
  17281. int isConnectorInitMode(int gun_index)
  17282. {
  17283. int tempIndex = 0;
  17284. int result = TRUE;
  17285. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17286. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17287. {
  17288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17289. {
  17290. tempIndex = ((gun_index==2) ? 1: 0);
  17291. }
  17292. else
  17293. {
  17294. tempIndex = gun_index;
  17295. }
  17296. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17297. {
  17298. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17299. {
  17300. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17301. } //end of the same index
  17302. }//end of for CHAdeMO_QUANTITY
  17303. }
  17304. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17305. {
  17306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17307. {
  17308. tempIndex = ((gun_index==2) ? 1: 0);
  17309. }
  17310. else
  17311. {
  17312. tempIndex = gun_index;
  17313. }
  17314. for (int index = 0; index < CCS_QUANTITY; index++)
  17315. {
  17316. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17317. {
  17318. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17319. } //end of the same index
  17320. } // end of for CCS_QUANTITY
  17321. }
  17322. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17323. {
  17324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17325. {
  17326. tempIndex = ((gun_index==2) ? 1: 0);
  17327. }
  17328. else
  17329. {
  17330. tempIndex = gun_index;
  17331. }
  17332. for (int index = 0; index < GB_QUANTITY; index++)
  17333. {
  17334. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17335. {
  17336. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17337. } //end of the same index
  17338. } // end of for GB_QUANTITY
  17339. }
  17340. else if(gunType[gun_index] == GUN_TYPE_DO)
  17341. {
  17342. tempIndex = gun_index;
  17343. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17344. {
  17345. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17346. {
  17347. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17348. } //end of the same index
  17349. }
  17350. }
  17351. else
  17352. {
  17353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17354. {
  17355. tempIndex = 2;
  17356. }
  17357. else
  17358. {
  17359. tempIndex = gun_index;
  17360. }
  17361. for (int index = 0; index < AC_QUANTITY; index++)
  17362. {
  17363. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17364. {
  17365. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17366. }//end of the same index
  17367. }//end of for AC_QUANTITY
  17368. }
  17369. return result;
  17370. }
  17371. void refreshProcDogTimer()
  17372. {
  17373. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17374. }
  17375. void InitialSystemValue(void)
  17376. {
  17377. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17378. locallistVersion=0;
  17379. BootNotificationInterval = 0;
  17380. authorizeRetryTimes = 0;
  17381. GunStatusInterval = 10;
  17382. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17383. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17384. //Hear Beat
  17385. HeartBeatWithNOResponse = 0;
  17386. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17387. FirstHeartBeat = 0;
  17388. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17389. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17390. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17391. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17392. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17393. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17394. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17395. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17396. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17397. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17398. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17399. //Status && ConnectorPlugIn Setting
  17400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17401. {
  17402. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17403. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17404. }
  17405. for (int index = 0; index < CCS_QUANTITY; index++)
  17406. {
  17407. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17408. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17409. }
  17410. for (int index = 0; index < GB_QUANTITY; index++)
  17411. {
  17412. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17413. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17414. }
  17415. for (int index = 0; index < AC_QUANTITY; index++)
  17416. {
  17417. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17418. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17419. }
  17420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17421. {
  17422. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17423. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17424. }
  17425. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17426. {
  17427. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17428. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17429. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17430. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17431. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17432. }
  17433. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17434. refreshStartTimer(&clientTime.Heartbeat);
  17435. sleep(1);
  17436. }
  17437. void LWS_Send(char *str)
  17438. {
  17439. //=====================================================
  17440. // Check InternetConn 0: disconnected, 1: connected
  17441. //====================================================
  17442. if(GetOcppConnStatus() == 0)
  17443. {
  17444. DEBUG_INFO("offline now !!!\n");
  17445. return;
  17446. }
  17447. // Only disable isWebsocketSendable operation initiated by charger
  17448. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17449. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17450. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17451. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17452. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17453. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17454. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17455. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17456. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17457. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17458. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17459. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17460. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17461. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17462. {
  17463. isWebsocketSendable = 0;
  17464. }
  17465. pthread_mutex_lock(&lock_send);
  17466. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17467. sprintf((char *)SendBuffer, "%s", str);
  17468. SendBufLen = strlen(str);
  17469. pthread_mutex_unlock(&lock_send);
  17470. lws_callback_on_writable(wsi_client);
  17471. //lws_service(context, 0);
  17472. //sleep(1);
  17473. }
  17474. void LWS_SendNow(char *str)
  17475. {
  17476. //=====================================================
  17477. // Check InternetConn 0: disconnected, 1: connected
  17478. //====================================================
  17479. if(GetOcppConnStatus() == 0)
  17480. {
  17481. DEBUG_INFO("offline now !!!\n");
  17482. return;
  17483. }
  17484. // Only disable isWebsocketSendable operation initiated by charger
  17485. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17486. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17487. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17488. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17489. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17490. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17491. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17492. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17493. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17494. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17495. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17496. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17497. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17498. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17499. {
  17500. isWebsocketSendable = 0;
  17501. }
  17502. pthread_mutex_lock(&lock_send);
  17503. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17504. sprintf((char *)SendBuffer, "%s", str);
  17505. SendBufLen = strlen(str);
  17506. pthread_mutex_unlock(&lock_send);
  17507. lws_callback_on_writable(wsi_client);
  17508. lws_service(context, 0);
  17509. //sleep(1);
  17510. }