MessageHandler.c 910 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. //==========================================
  735. // Check time passed since today
  736. //==========================================
  737. long long DiffTimebWithNow(struct timeb ST)
  738. {
  739. //return milli-second
  740. struct timeb ET;
  741. long long StartTime,StopTime;
  742. ftime(&ET);
  743. StartTime=(long long)ST.time;
  744. StopTime=(long long)ET.time;
  745. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  746. }
  747. int getTimePassSinceToday(uint8_t gun_index)
  748. {
  749. int result = -1;
  750. static time_t lastTime[4];
  751. time_t t;
  752. struct tm *tmStartToday;
  753. struct timeb tbStartToday;
  754. t=time(NULL);
  755. if(difftime(t, lastTime[gun_index])>0)
  756. {
  757. tmStartToday=localtime(&t);
  758. tmStartToday->tm_hour = 0;
  759. tmStartToday->tm_min = 0;
  760. tmStartToday->tm_sec = 0;
  761. tbStartToday.time = mktime(tmStartToday);
  762. tbStartToday.millitm = 0;
  763. result = DiffTimebWithNow(tbStartToday)/1000;
  764. lastTime[gun_index] = t;
  765. }
  766. return result;
  767. }
  768. void getNowDatetime(uint8_t *data)
  769. {
  770. time_t t = time(NULL);
  771. struct tm tm = *localtime(&t);
  772. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  773. }
  774. int syncDateTimeRTC(uint8_t *data)
  775. {
  776. struct ParsingResult
  777. {
  778. int result;
  779. int scanedElement;
  780. int year;
  781. int month;
  782. int mday;
  783. int hour;
  784. int min;
  785. int sec;
  786. int tz_hour;
  787. int tz_min;
  788. float minSec;
  789. }result;
  790. struct tm tmOrg;
  791. struct tm *tmTarget;
  792. struct timeb tbTarget;
  793. char buf[128];
  794. memset(&result, 0x00, sizeof(struct ParsingResult));
  795. result.result = PASS;
  796. if(strstr((char*)data, ".") != NULL)
  797. {
  798. // Original data with mini second
  799. if(strstr((char*)data, "Z") != NULL)
  800. {
  801. // Original data with Z
  802. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  803. &result.year,
  804. &result.month,
  805. &result.mday,
  806. &result.hour,
  807. &result.min,
  808. &result.sec,
  809. &result.minSec);
  810. }
  811. else
  812. {
  813. // Original data without Z
  814. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  815. &result.year,
  816. &result.month,
  817. &result.mday,
  818. &result.hour,
  819. &result.min,
  820. &result.sec,
  821. &result.minSec,
  822. &result.tz_hour,
  823. &result.tz_min);
  824. }
  825. }
  826. else
  827. {
  828. // Original data without mini second
  829. if(strstr((char*)data, "Z") != NULL)
  830. {
  831. // Original data with Z
  832. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  833. &result.year,
  834. &result.month,
  835. &result.mday,
  836. &result.hour,
  837. &result.min,
  838. &result.sec);
  839. }
  840. else
  841. {
  842. // Original data without Z
  843. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  844. &result.year,
  845. &result.month,
  846. &result.mday,
  847. &result.hour,
  848. &result.min,
  849. &result.sec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. tmOrg.tm_year = result.year - 1900;
  855. tmOrg.tm_mon = result.month - 1;
  856. tmOrg.tm_mday = result.mday;
  857. tmOrg.tm_hour = result.hour;
  858. tmOrg.tm_min = result.min;
  859. tmOrg.tm_sec = result.sec;
  860. tmOrg.tm_gmtoff = 0;
  861. tbTarget.time = mktime(&tmOrg);
  862. tbTarget.timezone = 0;
  863. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  864. tmTarget = gmtime(&tbTarget.time);
  865. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  866. //DEBUG_INFO(" org date time: %s\n", data);
  867. //DEBUG_INFO("parse date time: %s\n", buf);
  868. system(buf);
  869. system("/sbin/hwclock -w --systohc");
  870. if(result.scanedElement < 6)
  871. result.result = FAIL;
  872. return result.result;
  873. }
  874. //==========================================
  875. // GetCompositeSchedule logic related function
  876. //==========================================
  877. int DiffTimebSec(struct timeb ST, struct timeb ET)
  878. {
  879. //return milli-second
  880. unsigned int StartTime,StopTime;
  881. StartTime=(unsigned int)ST.time;
  882. StopTime=(unsigned int)ET.time;
  883. return (StopTime-StartTime);
  884. }
  885. int DiffTimebWithNowSec(struct timeb ST)
  886. {
  887. //return milli-second
  888. struct timeb ET;
  889. unsigned int StartTime,StopTime;
  890. ftime(&ET);
  891. StartTime=(unsigned int)ST.time;
  892. StopTime=(unsigned int)ET.time;
  893. return (StopTime-StartTime);
  894. }
  895. int getStartStop(uint8_t *start, uint8_t *stop)
  896. {
  897. int result = -1;
  898. struct tm tmStart;
  899. struct timeb tbStart;
  900. struct tm tmStop;
  901. struct timeb tbStop;
  902. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  903. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  904. {
  905. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  906. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  907. tmStart.tm_year -= 1900;
  908. tmStart.tm_mon -= 1;
  909. tbStart.time = mktime(&tmStart);
  910. tbStart.millitm = 0;
  911. tmStop.tm_year -= 1900;
  912. tmStop.tm_mon -= 1;
  913. tbStop.time = mktime(&tmStop);
  914. tbStop.millitm = 0;
  915. result = DiffTimebSec(tbStart, tbStop);
  916. //DEBUG_INFO("getStartStop(): %d\n", result);
  917. }
  918. else
  919. {
  920. DEBUG_WARN("Start or stop date parsing error.\r\n");
  921. }
  922. return result;
  923. }
  924. int isOvertNow(uint8_t *start)
  925. {
  926. int result = NO;
  927. struct ParsingResult
  928. {
  929. int result;
  930. int scanedElement;
  931. int year;
  932. int month;
  933. int mday;
  934. int hour;
  935. int min;
  936. int sec;
  937. int tz_hour;
  938. int tz_min;
  939. float minSec;
  940. }parsingResult;
  941. struct tm tmStart;
  942. struct timeb tbStart;
  943. if(strstr((char*)start, ".") != NULL)
  944. {
  945. // Original data with mini second
  946. if(strstr((char*)start, "Z") != NULL)
  947. {
  948. // Original data with Z
  949. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  950. &parsingResult.year,
  951. &parsingResult.month,
  952. &parsingResult.mday,
  953. &parsingResult.hour,
  954. &parsingResult.min,
  955. &parsingResult.sec,
  956. &parsingResult.minSec);
  957. }
  958. else
  959. {
  960. // Original data without Z
  961. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  962. &parsingResult.year,
  963. &parsingResult.month,
  964. &parsingResult.mday,
  965. &parsingResult.hour,
  966. &parsingResult.min,
  967. &parsingResult.sec,
  968. &parsingResult.minSec,
  969. &parsingResult.tz_hour,
  970. &parsingResult.tz_min);
  971. }
  972. }
  973. else
  974. {
  975. // Original data without mini second
  976. if(strstr((char*)start, "Z") != NULL)
  977. {
  978. // Original data with Z
  979. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  980. &parsingResult.year,
  981. &parsingResult.month,
  982. &parsingResult.mday,
  983. &parsingResult.hour,
  984. &parsingResult.min,
  985. &parsingResult.sec);
  986. }
  987. else
  988. {
  989. // Original data without Z
  990. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  991. &parsingResult.year,
  992. &parsingResult.month,
  993. &parsingResult.mday,
  994. &parsingResult.hour,
  995. &parsingResult.min,
  996. &parsingResult.sec,
  997. &parsingResult.tz_hour,
  998. &parsingResult.tz_min);
  999. }
  1000. }
  1001. if(parsingResult.scanedElement >= 6)
  1002. {
  1003. tmStart.tm_year = parsingResult.year - 1900;
  1004. tmStart.tm_mon = parsingResult.month - 1;
  1005. tmStart.tm_mday = parsingResult.mday;
  1006. tmStart.tm_hour = parsingResult.hour;
  1007. tmStart.tm_min = parsingResult.min;
  1008. tmStart.tm_sec = parsingResult.sec;
  1009. tmStart.tm_gmtoff = 0;
  1010. tbStart.time = mktime(&tmStart);
  1011. tbStart.timezone = 0;
  1012. tbStart.millitm = 0;
  1013. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1014. if(DiffTimebWithNowSec(tbStart) <= 0)
  1015. result = NO;
  1016. else
  1017. result = YES;
  1018. }
  1019. else
  1020. {
  1021. DEBUG_WARN("Start date parsing error.\n");
  1022. }
  1023. return result;
  1024. }
  1025. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1026. {
  1027. int result = -1;
  1028. struct tm tmStart;
  1029. struct timeb tbStart;
  1030. struct tm tmStop;
  1031. struct timeb tbStop;
  1032. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1033. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1034. {
  1035. tmStart.tm_year -= 1900;
  1036. tmStart.tm_mon -= 1;
  1037. tbStart.time = mktime(&tmStart);
  1038. tbStart.millitm = 0;
  1039. tmStop.tm_year -= 1900;
  1040. tmStop.tm_mon -= 1;
  1041. tbStop.time = mktime(&tmStop);
  1042. tbStop.millitm = 0;
  1043. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1044. }
  1045. return result;
  1046. }
  1047. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1048. {
  1049. FILE *fp;
  1050. char profileFileName[128];
  1051. char *line = NULL;
  1052. size_t len = 0;
  1053. time_t CurrentTime;
  1054. struct tm *tmComposite;
  1055. struct StructChargingProfile maxProfile;
  1056. uint8_t limitMax=0;
  1057. int compositePeriodIdx = 0;
  1058. CurrentTime = time(NULL);
  1059. tmComposite=localtime(&CurrentTime);
  1060. 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);
  1061. if(isUnitA)
  1062. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1063. else
  1064. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1065. compositeProfile->ChargingSchedule.Duration = durationReq;
  1066. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1067. {
  1068. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1069. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1070. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1071. }
  1072. compositeProfile->ChargingProfileId = 0;
  1073. compositeProfile->StackLevel = 99 ;
  1074. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1075. maxProfile.ChargingProfileId = -1;
  1076. maxProfile.ChargingSchedule.Duration = -1;
  1077. system("rm -f /tmp/*.json");
  1078. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1079. // Search max profile
  1080. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1081. if((access(profileFileName, F_OK))!=-1)
  1082. {
  1083. fp = fopen(profileFileName, "r");
  1084. while(getline(&line, &len, fp) != -1)
  1085. {
  1086. json_object *obj = NULL;
  1087. obj = json_tokener_parse(line);
  1088. if(is_error(obj))
  1089. {
  1090. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1091. }
  1092. else
  1093. {
  1094. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1095. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1096. )
  1097. {
  1098. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1099. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1100. )
  1101. {
  1102. struct tm tmFrom, tmTo;
  1103. struct timeb tbFrom, tbTo;
  1104. 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) &&
  1105. (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))
  1106. {
  1107. tmFrom.tm_year -= 1900;
  1108. tmFrom.tm_mon -= 1;
  1109. tbFrom.time = mktime(&tmFrom);
  1110. tmTo.tm_year -= 1900;
  1111. tmTo.tm_mon -= 1;
  1112. tbTo.time = mktime(&tmTo);
  1113. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1114. {
  1115. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1116. {
  1117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1118. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1119. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1120. }
  1121. maxProfile.ChargingProfileId = -1;
  1122. maxProfile.StackLevel = -1;
  1123. if(maxProfile.ChargingProfileId == -1)
  1124. DEBUG_INFO("MaxProfile found.\n");
  1125. else
  1126. DEBUG_INFO("MaxProfile updated.\n");
  1127. // Required item
  1128. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1129. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1130. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1131. if(isUnitA)
  1132. {
  1133. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1134. 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++)
  1135. {
  1136. 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"));
  1137. 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?
  1138. 3:
  1139. 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")));
  1140. 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")));
  1141. }
  1142. }
  1143. else
  1144. {
  1145. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1146. 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++)
  1147. {
  1148. 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"));
  1149. 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?
  1150. 3:
  1151. 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")));
  1152. 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));
  1153. }
  1154. }
  1155. // Optional item
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1157. {
  1158. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1159. }
  1160. else
  1161. {
  1162. sprintf((char*)maxProfile.ValidFrom, " ");
  1163. }
  1164. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1165. {
  1166. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1167. }
  1168. else
  1169. {
  1170. sprintf((char*)maxProfile.ValidTo, " ");
  1171. }
  1172. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1173. {
  1174. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1175. }
  1176. else
  1177. {
  1178. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1179. }
  1180. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1181. {
  1182. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.TransactionId = -1;
  1187. }
  1188. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1189. {
  1190. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1191. }
  1192. else
  1193. {
  1194. maxProfile.ChargingSchedule.Duration = 86400;
  1195. }
  1196. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1197. {
  1198. 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")));
  1199. }
  1200. else
  1201. {
  1202. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1203. }
  1204. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1205. {
  1206. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1207. }
  1208. else
  1209. {
  1210. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1211. }
  1212. }
  1213. }
  1214. }
  1215. else
  1216. {
  1217. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1218. {
  1219. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1220. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1221. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1222. }
  1223. maxProfile.ChargingProfileId = -1;
  1224. maxProfile.StackLevel = -1;
  1225. if(maxProfile.ChargingProfileId == -1)
  1226. DEBUG_INFO("MaxProfile found.\n");
  1227. else
  1228. DEBUG_INFO("MaxProfile updated.\n");
  1229. // Required item
  1230. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1231. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1232. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1233. if(isUnitA)
  1234. {
  1235. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1236. 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++)
  1237. {
  1238. 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"));
  1239. 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?
  1240. 3:
  1241. 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")));
  1242. 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")));
  1243. }
  1244. }
  1245. else
  1246. {
  1247. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1248. 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++)
  1249. {
  1250. 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"));
  1251. 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?
  1252. 3:
  1253. 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")));
  1254. 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));
  1255. }
  1256. }
  1257. // Optional item
  1258. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1259. {
  1260. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1261. }
  1262. else
  1263. {
  1264. sprintf((char*)maxProfile.ValidFrom, " ");
  1265. }
  1266. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1267. {
  1268. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1269. }
  1270. else
  1271. {
  1272. sprintf((char*)maxProfile.ValidTo, " ");
  1273. }
  1274. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1275. {
  1276. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1277. }
  1278. else
  1279. {
  1280. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1281. }
  1282. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1283. {
  1284. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1285. }
  1286. else
  1287. {
  1288. maxProfile.TransactionId = -1;
  1289. }
  1290. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1291. {
  1292. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1293. }
  1294. else
  1295. {
  1296. maxProfile.ChargingSchedule.Duration = 86400;
  1297. }
  1298. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1299. {
  1300. 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")));
  1301. }
  1302. else
  1303. {
  1304. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1305. }
  1306. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1307. {
  1308. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1309. }
  1310. else
  1311. {
  1312. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. json_object_put(obj);
  1318. }
  1319. fclose(fp);
  1320. /*
  1321. if(maxProfile.ChargingProfileId !=-1)
  1322. {
  1323. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1324. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1325. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1326. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1327. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1328. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1329. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1330. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1331. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1332. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1333. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1334. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1335. {
  1336. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1337. {
  1338. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1339. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1340. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1341. }
  1342. }
  1343. }
  1344. else
  1345. DEBUG_INFO("MaxProfile not found.\n");
  1346. DEBUG_INFO("------------------------------------\n");*/
  1347. }
  1348. if(maxProfile.ChargingProfileId != -1)
  1349. {
  1350. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1351. {
  1352. if(maxProfile.ChargingSchedule.Duration != -1)
  1353. {
  1354. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1355. 0:
  1356. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1357. }
  1358. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1359. {
  1360. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1361. {
  1362. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1363. 0:
  1364. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1365. if(idxPeriod > 0)
  1366. {
  1367. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1368. {
  1369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1376. {
  1377. if(maxProfile.ChargingSchedule.Duration != -1)
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1380. }
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1384. {
  1385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1386. if(idxPeriod > 0)
  1387. {
  1388. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1389. {
  1390. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. else
  1397. {
  1398. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1399. {
  1400. if(maxProfile.ChargingSchedule.Duration != -1)
  1401. {
  1402. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1403. 0:
  1404. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1405. }
  1406. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1407. {
  1408. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1409. {
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1411. 0:
  1412. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1413. if(idxPeriod > 0)
  1414. {
  1415. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1416. {
  1417. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. }
  1423. else
  1424. {
  1425. if(maxProfile.ChargingSchedule.Duration != -1)
  1426. {
  1427. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1428. 0:
  1429. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1430. }
  1431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1432. {
  1433. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1434. {
  1435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1436. 0:
  1437. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1438. if(idxPeriod > 0)
  1439. {
  1440. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1441. {
  1442. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. /*
  1450. DEBUG_INFO("MaxProfile after align.\n");
  1451. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1452. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1453. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1454. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1455. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1456. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1457. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1458. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1459. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1460. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1461. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1463. {
  1464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1465. {
  1466. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1467. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1468. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1469. }
  1470. }
  1471. DEBUG_INFO("------------------------------------\n");*/
  1472. }
  1473. // Find each profile period quantity
  1474. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1475. {
  1476. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1477. limitMax = idx+1;
  1478. }
  1479. if(maxProfile.ChargingProfileId != -1)
  1480. {
  1481. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1482. {
  1483. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1484. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1485. (maxProfile.ChargingSchedule.Duration > 0))
  1486. {
  1487. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1488. {
  1489. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1490. compositePeriodIdx++;
  1491. }
  1492. else
  1493. {
  1494. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1495. }
  1496. }
  1497. }
  1498. }
  1499. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1500. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1501. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1502. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1503. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1504. {
  1505. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1506. {
  1507. compositeProfile->ChargingProfileId = 1;
  1508. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1509. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1510. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1511. }
  1512. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1514. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1516. }
  1517. if(line)
  1518. free(line);
  1519. }
  1520. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1521. {
  1522. FILE *fp;
  1523. char profileFileName[128];
  1524. char *line = NULL;
  1525. size_t len = 0;
  1526. time_t CurrentTime;
  1527. struct tm *tmComposite;
  1528. struct StructChargingProfile maxProfile;
  1529. struct StructChargingProfile defaultTxProfile;
  1530. struct StructChargingProfile txProfile;
  1531. struct StructChargingSchedulePeriod tmpPeriod;
  1532. uint8_t limitMax=0;
  1533. uint8_t limitDef=0;
  1534. uint8_t limitTx=0;
  1535. int compositePeriodIdx = 0;
  1536. CurrentTime = time(NULL);
  1537. tmComposite=localtime(&CurrentTime);
  1538. 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);
  1539. if(isUnitA)
  1540. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1541. else
  1542. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1543. compositeProfile->ChargingSchedule.Duration = durationReq;
  1544. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1545. {
  1546. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1547. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1548. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1549. }
  1550. compositeProfile->ChargingProfileId = 0;
  1551. compositeProfile->StackLevel = 99 ;
  1552. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1553. maxProfile.ChargingProfileId = -1;
  1554. defaultTxProfile.ChargingProfileId = -1;
  1555. txProfile.ChargingProfileId = -1;
  1556. maxProfile.ChargingSchedule.Duration = -1;
  1557. defaultTxProfile.ChargingSchedule.Duration = -1;
  1558. txProfile.ChargingSchedule.Duration = -1;
  1559. system("rm -f /tmp/*.json");
  1560. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1561. /*
  1562. * Search valid charging profile
  1563. */
  1564. //DEBUG_INFO("====================================\n");
  1565. // Search tx profile
  1566. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1567. if((access(profileFileName, F_OK))!=-1)
  1568. {
  1569. fp = fopen(profileFileName, "r");
  1570. while(getline(&line, &len, fp) != -1)
  1571. {
  1572. json_object *obj = NULL;
  1573. obj = json_tokener_parse(line);
  1574. if(is_error(obj))
  1575. {
  1576. DEBUG_ERROR("Parse txProfile from file error.\n");
  1577. }
  1578. else
  1579. {
  1580. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1581. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1582. )
  1583. {
  1584. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1585. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1586. )
  1587. {
  1588. struct tm tmFrom, tmTo;
  1589. struct timeb tbFrom, tbTo;
  1590. 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) &&
  1591. (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))
  1592. {
  1593. tmFrom.tm_year -= 1900;
  1594. tmFrom.tm_mon -= 1;
  1595. tbFrom.time = mktime(&tmFrom);
  1596. tmTo.tm_year -= 1900;
  1597. tmTo.tm_mon -= 1;
  1598. tbTo.time = mktime(&tmTo);
  1599. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1600. {
  1601. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1602. {
  1603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1604. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1605. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1606. }
  1607. txProfile.ChargingProfileId = -1;
  1608. txProfile.StackLevel = -1;
  1609. if(txProfile.ChargingProfileId == -1)
  1610. DEBUG_INFO("TxProfile found.\n");
  1611. else
  1612. DEBUG_INFO("TxProfile updated.\n");
  1613. // Required item
  1614. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1615. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1616. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1617. if(isUnitA)
  1618. {
  1619. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1620. 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++)
  1621. {
  1622. 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"));
  1623. 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?
  1624. 3:
  1625. 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")));
  1626. 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")));
  1627. }
  1628. }
  1629. else
  1630. {
  1631. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1632. 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++)
  1633. {
  1634. 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"));
  1635. 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?
  1636. 3:
  1637. 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")));
  1638. 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));
  1639. }
  1640. }
  1641. // Optional item
  1642. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1643. {
  1644. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1645. }
  1646. else
  1647. {
  1648. sprintf((char*)txProfile.ValidFrom, " ");
  1649. }
  1650. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1651. {
  1652. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1653. }
  1654. else
  1655. {
  1656. sprintf((char*)txProfile.ValidTo, " ");
  1657. }
  1658. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1659. {
  1660. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1661. }
  1662. else
  1663. {
  1664. sprintf((char*)txProfile.RecurrencyKind, " ");
  1665. }
  1666. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1667. {
  1668. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1669. }
  1670. else
  1671. {
  1672. txProfile.TransactionId = -1;
  1673. }
  1674. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1675. {
  1676. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1677. }
  1678. else
  1679. {
  1680. txProfile.ChargingSchedule.Duration = 86400;
  1681. }
  1682. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1683. {
  1684. 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")));
  1685. }
  1686. else
  1687. {
  1688. 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));
  1689. }
  1690. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1691. {
  1692. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1693. }
  1694. else
  1695. {
  1696. txProfile.ChargingSchedule.MinChargingRate = -1;
  1697. }
  1698. }
  1699. }
  1700. }
  1701. else
  1702. {
  1703. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1704. {
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1706. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1707. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1708. }
  1709. txProfile.ChargingProfileId = -1;
  1710. txProfile.StackLevel = -1;
  1711. if(txProfile.ChargingProfileId == -1)
  1712. DEBUG_INFO("TxProfile found.\n");
  1713. else
  1714. DEBUG_INFO("TxProfile updated.\n");
  1715. // Required item
  1716. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1717. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1718. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1719. if(isUnitA)
  1720. {
  1721. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1722. 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++)
  1723. {
  1724. 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"));
  1725. 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?
  1726. 3:
  1727. 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")));
  1728. 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")));
  1729. }
  1730. }
  1731. else
  1732. {
  1733. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1734. 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++)
  1735. {
  1736. 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"));
  1737. 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?
  1738. 3:
  1739. 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")));
  1740. 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));
  1741. }
  1742. }
  1743. // Optional item
  1744. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1745. {
  1746. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1747. }
  1748. else
  1749. {
  1750. sprintf((char*)txProfile.ValidFrom, " ");
  1751. }
  1752. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1753. {
  1754. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1755. }
  1756. else
  1757. {
  1758. sprintf((char*)txProfile.ValidTo, " ");
  1759. }
  1760. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1761. {
  1762. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1763. }
  1764. else
  1765. {
  1766. sprintf((char*)txProfile.RecurrencyKind, " ");
  1767. }
  1768. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1769. {
  1770. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1771. }
  1772. else
  1773. {
  1774. txProfile.TransactionId = -1;
  1775. }
  1776. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1777. {
  1778. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1779. }
  1780. else
  1781. {
  1782. txProfile.ChargingSchedule.Duration = 86400;
  1783. }
  1784. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1785. {
  1786. 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")));
  1787. }
  1788. else
  1789. {
  1790. 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));
  1791. }
  1792. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1793. {
  1794. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1795. }
  1796. else
  1797. {
  1798. txProfile.ChargingSchedule.MinChargingRate = -1;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. json_object_put(obj);
  1804. }
  1805. fclose(fp);
  1806. /*
  1807. if(txProfile.ChargingProfileId != -1)
  1808. {
  1809. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1810. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1811. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1812. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1813. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1814. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1815. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1816. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1817. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1818. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1819. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1820. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1821. {
  1822. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1823. {
  1824. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1825. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1826. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1827. }
  1828. }
  1829. }
  1830. else
  1831. DEBUG_INFO("TxProfile not found.\n");*/
  1832. }
  1833. // Search default tx profile
  1834. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1835. if((access(profileFileName, F_OK))==-1)
  1836. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1837. if((access(profileFileName, F_OK))!=-1)
  1838. {
  1839. fp = fopen(profileFileName, "r");
  1840. while(getline(&line, &len, fp) != -1)
  1841. {
  1842. json_object *obj = NULL;
  1843. obj = json_tokener_parse(line);
  1844. if(is_error(obj))
  1845. {
  1846. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1847. }
  1848. else
  1849. {
  1850. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1851. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1852. )
  1853. {
  1854. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1855. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1856. )
  1857. {
  1858. struct tm tmFrom, tmTo;
  1859. struct timeb tbFrom, tbTo;
  1860. 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) &&
  1861. (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))
  1862. {
  1863. tmFrom.tm_year -= 1900;
  1864. tmFrom.tm_mon -= 1;
  1865. tbFrom.time = mktime(&tmFrom);
  1866. tmTo.tm_year -= 1900;
  1867. tmTo.tm_mon -= 1;
  1868. tbTo.time = mktime(&tmTo);
  1869. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1870. {
  1871. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1874. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1876. }
  1877. defaultTxProfile.ChargingProfileId = -1;
  1878. defaultTxProfile.StackLevel = -1;
  1879. if(defaultTxProfile.ChargingProfileId == -1)
  1880. DEBUG_INFO("TxDefaultProfile found.\n");
  1881. else
  1882. DEBUG_INFO("TxDefaultProfile updated.\n");
  1883. // Required item
  1884. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1885. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1886. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1887. if(isUnitA)
  1888. {
  1889. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1890. 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++)
  1891. {
  1892. 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"));
  1893. 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?
  1894. 3:
  1895. 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")));
  1896. 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")));
  1897. }
  1898. }
  1899. else
  1900. {
  1901. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1902. 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++)
  1903. {
  1904. 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"));
  1905. 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?
  1906. 3:
  1907. 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")));
  1908. 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));
  1909. }
  1910. }
  1911. // Optional item
  1912. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1913. {
  1914. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1915. }
  1916. else
  1917. {
  1918. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1919. }
  1920. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1921. {
  1922. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1923. }
  1924. else
  1925. {
  1926. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1927. }
  1928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1929. {
  1930. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1931. }
  1932. else
  1933. {
  1934. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1935. }
  1936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1937. {
  1938. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1939. }
  1940. else
  1941. {
  1942. defaultTxProfile.TransactionId = -1;
  1943. }
  1944. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1945. {
  1946. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1947. }
  1948. else
  1949. {
  1950. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1951. }
  1952. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1953. {
  1954. 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")));
  1955. }
  1956. else
  1957. {
  1958. 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));
  1959. }
  1960. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1961. {
  1962. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1963. }
  1964. else
  1965. {
  1966. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1967. }
  1968. }
  1969. }
  1970. }
  1971. else
  1972. {
  1973. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1974. {
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1977. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1978. }
  1979. defaultTxProfile.ChargingProfileId = -1;
  1980. defaultTxProfile.StackLevel = -1;
  1981. if(defaultTxProfile.ChargingProfileId == -1)
  1982. DEBUG_INFO("TxDefaultProfile found.\n");
  1983. else
  1984. DEBUG_INFO("TxDefaultProfile updated.\n");
  1985. // Required item
  1986. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1987. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1988. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1989. if(isUnitA)
  1990. {
  1991. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1992. 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++)
  1993. {
  1994. 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"));
  1995. 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?
  1996. 3:
  1997. 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")));
  1998. 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")));
  1999. }
  2000. }
  2001. else
  2002. {
  2003. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2004. 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++)
  2005. {
  2006. 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"));
  2007. 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?
  2008. 3:
  2009. 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")));
  2010. 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));
  2011. }
  2012. }
  2013. // Optional item
  2014. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2015. {
  2016. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2017. }
  2018. else
  2019. {
  2020. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2021. }
  2022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2023. {
  2024. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2025. }
  2026. else
  2027. {
  2028. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2029. }
  2030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2031. {
  2032. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2033. }
  2034. else
  2035. {
  2036. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2037. }
  2038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2039. {
  2040. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2041. }
  2042. else
  2043. {
  2044. defaultTxProfile.TransactionId = -1;
  2045. }
  2046. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2047. {
  2048. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2049. }
  2050. else
  2051. {
  2052. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2053. }
  2054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2055. {
  2056. 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")));
  2057. }
  2058. else
  2059. {
  2060. 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));
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2063. {
  2064. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2065. }
  2066. else
  2067. {
  2068. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2069. }
  2070. }
  2071. }
  2072. }
  2073. json_object_put(obj);
  2074. }
  2075. fclose(fp);
  2076. /*
  2077. if(defaultTxProfile.ChargingProfileId != -1)
  2078. {
  2079. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2080. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2081. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2082. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2083. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2084. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2085. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2086. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2087. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2088. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2089. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2090. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2091. {
  2092. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2093. {
  2094. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2095. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2096. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2097. }
  2098. }
  2099. }
  2100. else
  2101. DEBUG_INFO("TxDefaultProfile not found.\n");
  2102. DEBUG_INFO("------------------------------------\n");*/
  2103. }
  2104. // Search max profile
  2105. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2106. if((access(profileFileName, F_OK))!=-1)
  2107. {
  2108. fp = fopen(profileFileName, "r");
  2109. while(getline(&line, &len, fp) != -1)
  2110. {
  2111. json_object *obj = NULL;
  2112. obj = json_tokener_parse(line);
  2113. if(is_error(obj))
  2114. {
  2115. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2116. }
  2117. else
  2118. {
  2119. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2120. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2121. )
  2122. {
  2123. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2124. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2125. )
  2126. {
  2127. struct tm tmFrom, tmTo;
  2128. struct timeb tbFrom, tbTo;
  2129. 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) &&
  2130. (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))
  2131. {
  2132. tmFrom.tm_year -= 1900;
  2133. tmFrom.tm_mon -= 1;
  2134. tbFrom.time = mktime(&tmFrom);
  2135. tmTo.tm_year -= 1900;
  2136. tmTo.tm_mon -= 1;
  2137. tbTo.time = mktime(&tmTo);
  2138. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2139. {
  2140. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2141. {
  2142. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2143. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2144. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2145. }
  2146. maxProfile.ChargingProfileId = -1;
  2147. maxProfile.StackLevel = -1;
  2148. if(maxProfile.ChargingProfileId == -1)
  2149. DEBUG_INFO("MaxProfile found.\n");
  2150. else
  2151. DEBUG_INFO("MaxProfile updated.\n");
  2152. // Required item
  2153. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2154. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2155. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2156. if(isUnitA)
  2157. {
  2158. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2159. 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++)
  2160. {
  2161. 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"));
  2162. 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?
  2163. 3:
  2164. 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")));
  2165. 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")));
  2166. }
  2167. }
  2168. else
  2169. {
  2170. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2171. 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++)
  2172. {
  2173. 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"));
  2174. 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?
  2175. 3:
  2176. 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")));
  2177. 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));
  2178. }
  2179. }
  2180. // Optional item
  2181. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2182. {
  2183. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2184. }
  2185. else
  2186. {
  2187. sprintf((char*)maxProfile.ValidFrom, " ");
  2188. }
  2189. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2190. {
  2191. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2192. }
  2193. else
  2194. {
  2195. sprintf((char*)maxProfile.ValidTo, " ");
  2196. }
  2197. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2198. {
  2199. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2200. }
  2201. else
  2202. {
  2203. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2204. }
  2205. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2206. {
  2207. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2208. }
  2209. else
  2210. {
  2211. maxProfile.TransactionId = -1;
  2212. }
  2213. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2214. {
  2215. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2216. }
  2217. else
  2218. {
  2219. maxProfile.ChargingSchedule.Duration = 86400;
  2220. }
  2221. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2222. {
  2223. 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")));
  2224. }
  2225. else
  2226. {
  2227. 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));
  2228. }
  2229. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2230. {
  2231. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2232. }
  2233. else
  2234. {
  2235. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2236. }
  2237. }
  2238. }
  2239. }
  2240. else
  2241. {
  2242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2243. {
  2244. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2245. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2246. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2247. }
  2248. maxProfile.ChargingProfileId = -1;
  2249. maxProfile.StackLevel = -1;
  2250. if(maxProfile.ChargingProfileId == -1)
  2251. DEBUG_INFO("MaxProfile found.\n");
  2252. else
  2253. DEBUG_INFO("MaxProfile updated.\n");
  2254. // Required item
  2255. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2256. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2257. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2258. if(isUnitA)
  2259. {
  2260. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2261. 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++)
  2262. {
  2263. 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"));
  2264. 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?
  2265. 3:
  2266. 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")));
  2267. 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")));
  2268. }
  2269. }
  2270. else
  2271. {
  2272. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2273. 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++)
  2274. {
  2275. 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"));
  2276. 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?
  2277. 3:
  2278. 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")));
  2279. 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));
  2280. }
  2281. }
  2282. // Optional item
  2283. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2284. {
  2285. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2286. }
  2287. else
  2288. {
  2289. sprintf((char*)maxProfile.ValidFrom, " ");
  2290. }
  2291. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2292. {
  2293. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2294. }
  2295. else
  2296. {
  2297. sprintf((char*)maxProfile.ValidTo, " ");
  2298. }
  2299. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2300. {
  2301. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2302. }
  2303. else
  2304. {
  2305. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2306. }
  2307. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2308. {
  2309. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2310. }
  2311. else
  2312. {
  2313. maxProfile.TransactionId = -1;
  2314. }
  2315. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2316. {
  2317. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2318. }
  2319. else
  2320. {
  2321. maxProfile.ChargingSchedule.Duration = 86400;
  2322. }
  2323. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2324. {
  2325. 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")));
  2326. }
  2327. else
  2328. {
  2329. 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));
  2330. }
  2331. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2332. {
  2333. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2334. }
  2335. else
  2336. {
  2337. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2338. }
  2339. }
  2340. }
  2341. }
  2342. json_object_put(obj);
  2343. }
  2344. fclose(fp);
  2345. /*
  2346. if(maxProfile.ChargingProfileId !=-1)
  2347. {
  2348. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2349. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2350. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2351. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2352. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2353. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2354. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2355. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2356. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2357. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2358. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2359. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2360. {
  2361. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2362. {
  2363. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2364. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2365. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2366. }
  2367. }
  2368. }
  2369. else
  2370. DEBUG_INFO("MaxProfile not found.\n");
  2371. DEBUG_INFO("------------------------------------\n");*/
  2372. }
  2373. /*
  2374. * Align found profile start schedule & periods
  2375. */
  2376. //DEBUG_INFO("====================================\n");
  2377. /*
  2378. // For local test usage, force modify found profile start schedule info
  2379. 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);
  2380. 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);
  2381. 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);
  2382. */
  2383. if(txProfile.ChargingProfileId != -1)
  2384. {
  2385. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2386. {
  2387. if(txProfile.ChargingSchedule.Duration != -1)
  2388. {
  2389. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2390. 0:
  2391. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2392. }
  2393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2394. {
  2395. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2396. {
  2397. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2398. 0:
  2399. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2400. if(idxPeriod > 0)
  2401. {
  2402. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2403. {
  2404. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2411. {
  2412. if(txProfile.ChargingSchedule.Duration != -1)
  2413. {
  2414. 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?
  2415. 0:
  2416. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2417. }
  2418. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2419. {
  2420. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2421. {
  2422. 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?
  2423. 0:
  2424. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2425. if(idxPeriod > 0)
  2426. {
  2427. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2428. {
  2429. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. else
  2436. {
  2437. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2438. {
  2439. if(txProfile.ChargingSchedule.Duration != -1)
  2440. {
  2441. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2442. 0:
  2443. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2444. }
  2445. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2446. {
  2447. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2448. {
  2449. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2450. 0:
  2451. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2452. if(idxPeriod > 0)
  2453. {
  2454. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2455. {
  2456. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2457. }
  2458. }
  2459. }
  2460. }
  2461. }
  2462. else
  2463. {
  2464. if(txProfile.ChargingSchedule.Duration != -1)
  2465. {
  2466. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2467. 0:
  2468. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2469. }
  2470. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2471. {
  2472. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2473. {
  2474. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2475. 0:
  2476. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2477. if(idxPeriod > 0)
  2478. {
  2479. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2480. {
  2481. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2482. }
  2483. }
  2484. }
  2485. }
  2486. }
  2487. }
  2488. /*
  2489. DEBUG_INFO("txProfile after align.\n");
  2490. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2491. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2492. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2493. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2494. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2495. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2496. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2497. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2498. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2499. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2500. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2502. {
  2503. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2504. {
  2505. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2506. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2507. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2508. }
  2509. }*/
  2510. }
  2511. if(defaultTxProfile.ChargingProfileId != -1)
  2512. {
  2513. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2514. {
  2515. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2516. {
  2517. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2518. 0:
  2519. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2520. }
  2521. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2522. {
  2523. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2524. {
  2525. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2526. 0:
  2527. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2528. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2529. {
  2530. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2531. }
  2532. if(idxPeriod > 0)
  2533. {
  2534. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2535. {
  2536. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2537. }
  2538. }
  2539. }
  2540. }
  2541. }
  2542. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2543. {
  2544. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2545. {
  2546. 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?
  2547. 0:
  2548. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2549. }
  2550. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2551. {
  2552. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2553. {
  2554. 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?
  2555. 0:
  2556. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2557. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2558. {
  2559. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2560. }
  2561. if(idxPeriod > 0)
  2562. {
  2563. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2564. {
  2565. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. else
  2572. {
  2573. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2574. {
  2575. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2576. {
  2577. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2578. 0:
  2579. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2580. }
  2581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2582. {
  2583. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2584. {
  2585. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2586. 0:
  2587. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2588. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2589. {
  2590. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2591. }
  2592. if(idxPeriod > 0)
  2593. {
  2594. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2595. {
  2596. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2597. }
  2598. }
  2599. }
  2600. }
  2601. }
  2602. else
  2603. {
  2604. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2605. {
  2606. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2607. 0:
  2608. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2609. }
  2610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2611. {
  2612. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2613. {
  2614. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2615. 0:
  2616. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2617. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2618. {
  2619. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2620. }
  2621. if(idxPeriod > 0)
  2622. {
  2623. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2624. {
  2625. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2626. }
  2627. }
  2628. }
  2629. }
  2630. }
  2631. }
  2632. /*
  2633. DEBUG_INFO("defaultTxProfile after align.\n");
  2634. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2635. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2636. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2637. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2638. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2639. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2640. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2641. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2642. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2643. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2644. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2645. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2646. {
  2647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2648. {
  2649. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2650. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2651. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2652. }
  2653. }
  2654. DEBUG_INFO("------------------------------------\n");*/
  2655. }
  2656. if(maxProfile.ChargingProfileId != -1)
  2657. {
  2658. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2659. {
  2660. if(maxProfile.ChargingSchedule.Duration != -1)
  2661. {
  2662. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2663. 0:
  2664. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2665. }
  2666. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2667. {
  2668. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2669. {
  2670. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2671. 0:
  2672. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2673. if(idxPeriod > 0)
  2674. {
  2675. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2676. {
  2677. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2684. {
  2685. if(maxProfile.ChargingSchedule.Duration != -1)
  2686. {
  2687. 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?
  2688. 0:
  2689. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2690. }
  2691. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2692. {
  2693. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2694. {
  2695. 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?
  2696. 0:
  2697. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2698. if(idxPeriod > 0)
  2699. {
  2700. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2701. {
  2702. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2703. }
  2704. }
  2705. }
  2706. }
  2707. }
  2708. else
  2709. {
  2710. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2711. {
  2712. if(maxProfile.ChargingSchedule.Duration != -1)
  2713. {
  2714. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2715. 0:
  2716. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2717. }
  2718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2719. {
  2720. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2721. {
  2722. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2723. 0:
  2724. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2725. if(idxPeriod > 0)
  2726. {
  2727. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2728. {
  2729. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2730. }
  2731. }
  2732. }
  2733. }
  2734. }
  2735. else
  2736. {
  2737. if(maxProfile.ChargingSchedule.Duration != -1)
  2738. {
  2739. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2740. 0:
  2741. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2742. }
  2743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2744. {
  2745. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2746. {
  2747. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2748. 0:
  2749. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2750. if(idxPeriod > 0)
  2751. {
  2752. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2753. {
  2754. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. }
  2761. /*
  2762. DEBUG_INFO("MaxProfile after align.\n");
  2763. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2764. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2765. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2766. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2767. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2768. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2769. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2770. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2771. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2772. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2773. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2775. {
  2776. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2777. {
  2778. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2779. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2780. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2781. }
  2782. }
  2783. DEBUG_INFO("------------------------------------\n");*/
  2784. }
  2785. /*
  2786. * Merge to conposite schedule
  2787. */
  2788. //DEBUG_INFO("====================================\n");
  2789. // Find each profile period quantity
  2790. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2791. {
  2792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2793. limitMax = idx+1;
  2794. }
  2795. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2796. {
  2797. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2798. limitDef = idx+1;
  2799. }
  2800. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2801. {
  2802. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2803. limitTx = idx+1;
  2804. }
  2805. // TxProfile found, composite schedule based on it
  2806. if(txProfile.ChargingProfileId != -1)
  2807. {
  2808. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2809. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2810. {
  2811. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2812. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2813. (txProfile.ChargingSchedule.Duration > 0))
  2814. {
  2815. if(maxProfile.ChargingProfileId != -1)
  2816. {
  2817. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2818. {
  2819. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2820. {
  2821. if((maxProfile.ChargingSchedule.Duration > 0))
  2822. {
  2823. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2824. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2825. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2826. }
  2827. else
  2828. {
  2829. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2830. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2831. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2832. }
  2833. }
  2834. if(idxMaxPeriod == (limitMax-1))
  2835. {
  2836. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2837. {
  2838. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2839. {
  2840. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2841. compositePeriodIdx++;
  2842. }
  2843. else
  2844. {
  2845. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. else
  2852. {
  2853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2854. {
  2855. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2856. compositePeriodIdx++;
  2857. }
  2858. else
  2859. {
  2860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2861. }
  2862. }
  2863. }
  2864. if(idxTxPeriod == (limitTx-1))
  2865. {
  2866. if(defaultTxProfile.ChargingProfileId != -1)
  2867. {
  2868. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2869. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2870. {
  2871. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2872. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2873. (defaultTxProfile.ChargingSchedule.Duration>0))
  2874. {
  2875. if(maxProfile.ChargingProfileId != -1)
  2876. {
  2877. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2878. {
  2879. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2880. {
  2881. if((maxProfile.ChargingSchedule.Duration > 0))
  2882. {
  2883. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2884. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2885. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2886. }
  2887. else
  2888. {
  2889. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2890. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2891. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2892. }
  2893. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2894. {
  2895. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2896. {
  2897. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2898. compositePeriodIdx++;
  2899. }
  2900. else
  2901. {
  2902. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2903. }
  2904. }
  2905. // Delete duplicate period
  2906. if(compositePeriodIdx > 1)
  2907. {
  2908. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2909. {
  2910. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2911. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2912. compositePeriodIdx -= 1;
  2913. }
  2914. }
  2915. }
  2916. else
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2919. {
  2920. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2921. compositePeriodIdx++;
  2922. }
  2923. else
  2924. {
  2925. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2926. }
  2927. break;
  2928. }
  2929. }
  2930. }
  2931. else
  2932. {
  2933. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2934. {
  2935. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2936. compositePeriodIdx++;
  2937. }
  2938. else
  2939. {
  2940. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2950. else if(defaultTxProfile.ChargingProfileId != -1)
  2951. {
  2952. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2953. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2954. {
  2955. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2956. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2957. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2958. {
  2959. if(maxProfile.ChargingProfileId != -1)
  2960. {
  2961. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2962. {
  2963. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2964. {
  2965. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2966. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2967. if((maxProfile.ChargingSchedule.Duration > 0))
  2968. {
  2969. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2970. }
  2971. else
  2972. {
  2973. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2974. }
  2975. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2976. {
  2977. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2978. {
  2979. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2980. compositePeriodIdx++;
  2981. }
  2982. else
  2983. {
  2984. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2985. }
  2986. }
  2987. // Delete duplicate period
  2988. if(compositePeriodIdx > 1)
  2989. {
  2990. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2991. {
  2992. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2993. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2994. compositePeriodIdx -= 1;
  2995. }
  2996. }
  2997. }
  2998. else
  2999. {
  3000. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3001. {
  3002. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3003. compositePeriodIdx++;
  3004. }
  3005. else
  3006. {
  3007. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3008. }
  3009. break;
  3010. }
  3011. }
  3012. }
  3013. else
  3014. {
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3016. {
  3017. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3018. compositePeriodIdx++;
  3019. }
  3020. else
  3021. {
  3022. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3023. }
  3024. }
  3025. }
  3026. }
  3027. }
  3028. // Fill other period by MaxProfile
  3029. if(maxProfile.ChargingProfileId != -1)
  3030. {
  3031. if(compositePeriodIdx==0)
  3032. {
  3033. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3034. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3035. {
  3036. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3037. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3038. (maxProfile.ChargingSchedule.Duration > 0))
  3039. {
  3040. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3041. {
  3042. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3043. compositePeriodIdx++;
  3044. }
  3045. else
  3046. {
  3047. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3048. }
  3049. }
  3050. }
  3051. }
  3052. else
  3053. {
  3054. int lastCompositePeriodIdx = compositePeriodIdx;
  3055. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3056. {
  3057. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3058. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3059. (maxProfile.ChargingSchedule.Duration > 0))
  3060. {
  3061. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3062. {
  3063. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3064. {
  3065. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3066. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3067. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3068. }
  3069. else
  3070. {
  3071. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3072. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3073. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3074. }
  3075. }
  3076. if(tmpPeriod.Limit != -1)
  3077. {
  3078. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3079. {
  3080. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3081. {
  3082. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3083. compositePeriodIdx++;
  3084. }
  3085. else
  3086. {
  3087. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3088. }
  3089. }
  3090. // Delete duplicate period
  3091. if(compositePeriodIdx > 1)
  3092. {
  3093. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3094. {
  3095. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3096. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3097. compositePeriodIdx -= 1;
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. }
  3104. }
  3105. compositeProfile->ChargingSchedule.Duration = durationReq;
  3106. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3107. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3108. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3109. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3110. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3111. {
  3112. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3113. {
  3114. compositeProfile->ChargingProfileId = 1;
  3115. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3116. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3117. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3118. }
  3119. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3120. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3121. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3122. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3123. }
  3124. if(line)
  3125. free(line);
  3126. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3127. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3128. }
  3129. //==========================================
  3130. // Init all share memory
  3131. //==========================================
  3132. int InitShareMemory()
  3133. {
  3134. int result = PASS;
  3135. int MeterSMId;
  3136. //creat ShmSysConfigAndInfo
  3137. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3138. {
  3139. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3140. result = FAIL;
  3141. }
  3142. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3143. {
  3144. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3145. result = FAIL;
  3146. }
  3147. else
  3148. {}
  3149. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3150. {
  3151. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3152. result = FAIL;
  3153. }
  3154. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3155. {
  3156. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3157. result = FAIL;
  3158. }
  3159. else
  3160. {}
  3161. //creat ShmPsuData
  3162. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3163. {
  3164. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3165. result = FAIL;
  3166. }
  3167. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3168. {
  3169. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3170. result = FAIL;
  3171. }
  3172. else
  3173. {}
  3174. //link ShmOCPP16Data
  3175. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3176. {
  3177. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3178. result = FAIL;
  3179. }
  3180. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3181. {
  3182. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3183. result = FAIL;
  3184. }
  3185. else
  3186. {}
  3187. //creat ShmOCPP16DataPH
  3188. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3189. {
  3190. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3191. result = FAIL;
  3192. }
  3193. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3194. {
  3195. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3196. result = FAIL;
  3197. }
  3198. else
  3199. {}
  3200. /****************************** For Initial Settings************************************************/
  3201. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3202. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3203. // allocate Configuration memory address
  3204. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3205. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3206. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3207. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3208. //offline MeterValue Interval
  3209. TempMeterValueInterval = 0;
  3210. return result;
  3211. }
  3212. int ProcessShareMemory()
  3213. {
  3214. int result = PASS;
  3215. if(InitShareMemory() == FAIL)
  3216. {
  3217. DEBUG_ERROR("InitShareMemory NG\n");
  3218. if(ShmStatusCodeData!=NULL)
  3219. {
  3220. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3221. }
  3222. result = FAIL;
  3223. }
  3224. // Model name parsing
  3225. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3226. {
  3227. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3228. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3229. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3230. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3231. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3232. ) // 'D' means DC
  3233. {
  3234. // DO series
  3235. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3236. {
  3237. SystemInitial += 1;
  3238. gunTotalNumber += 1;
  3239. gunType[gun_index] = GUN_TYPE_DO;
  3240. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3241. {
  3242. case Gun_Type_Chademo:
  3243. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3244. break;
  3245. case Gun_Type_CCS_2:
  3246. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3247. break;
  3248. case Gun_Type_GB:
  3249. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3250. break;
  3251. case Gun_Type_AC:
  3252. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3253. break;
  3254. default:
  3255. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3256. break;
  3257. }
  3258. }
  3259. }
  3260. else
  3261. {
  3262. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3263. {
  3264. SystemInitial += 1;
  3265. gunTotalNumber += 1;
  3266. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3267. {
  3268. case Gun_Type_Chademo:
  3269. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3270. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3271. break;
  3272. case Gun_Type_CCS_2:
  3273. gunType[gun_index] = GUN_TYPE_CCS;
  3274. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3275. break;
  3276. case Gun_Type_GB:
  3277. gunType[gun_index] = GUN_TYPE_GBT;
  3278. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3279. break;
  3280. case Gun_Type_AC:
  3281. gunType[gun_index] = GUN_TYPE_AC;
  3282. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3283. break;
  3284. default:
  3285. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3286. break;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. else
  3292. {
  3293. DEBUG_ERROR("Model name parsing fail.\n");
  3294. result = FAIL;
  3295. }
  3296. if(result != PASS)sleep(5);
  3297. return result;
  3298. }
  3299. void checkRemoteStart(uint8_t connectorIdInt)
  3300. {
  3301. uint8_t tempIndex;
  3302. int result = PASS;
  3303. char cmdBuf[512];
  3304. //check Transaction active
  3305. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3306. {
  3307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3308. {
  3309. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3310. }
  3311. else
  3312. {
  3313. tempIndex = connectorIdInt -1;
  3314. }
  3315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3316. {
  3317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3318. {
  3319. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3320. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3321. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3322. {
  3323. //Reserved
  3324. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3325. }
  3326. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3327. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3328. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3329. {
  3330. //Reserved
  3331. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3332. result = FAIL;
  3333. goto end;
  3334. }
  3335. else
  3336. {
  3337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3339. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3340. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3341. {
  3342. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3343. result = FAIL;
  3344. goto end;
  3345. }
  3346. }//END FOR ELSE
  3347. }
  3348. }// END FOR CHAdeMO_QUANTITY
  3349. }
  3350. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3351. {
  3352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3353. {
  3354. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3355. }
  3356. else
  3357. {
  3358. tempIndex = connectorIdInt -1;
  3359. }
  3360. for (int index = 0; index < CCS_QUANTITY; index++)
  3361. {
  3362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3363. {
  3364. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3365. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3366. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3367. {
  3368. //Reserved
  3369. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3370. }
  3371. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3372. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3373. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3374. {
  3375. //Reserved
  3376. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3377. result = FAIL;
  3378. goto end;
  3379. }
  3380. else
  3381. {
  3382. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3383. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3384. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3385. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3386. {
  3387. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3388. result = FAIL;
  3389. goto end;
  3390. }
  3391. }// END FOR ELSE
  3392. }
  3393. }// END FOR CCS_QUANTITY
  3394. }
  3395. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3396. {
  3397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3398. {
  3399. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3400. }
  3401. else
  3402. {
  3403. tempIndex = connectorIdInt -1;
  3404. }
  3405. for (int index = 0; index < GB_QUANTITY; index++)
  3406. {
  3407. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3408. {
  3409. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3410. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3411. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3412. {
  3413. //Reserved
  3414. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3415. }
  3416. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3417. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3418. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3419. {
  3420. //Reserved
  3421. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3422. result = FAIL;
  3423. goto end;
  3424. }
  3425. else
  3426. {
  3427. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3429. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3430. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3431. {
  3432. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3433. result = FAIL;
  3434. goto end;
  3435. }
  3436. }// END FOR ELSE
  3437. }
  3438. } // END FOR GB_QUANTITY
  3439. }
  3440. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3441. {
  3442. tempIndex = connectorIdInt -1;
  3443. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3444. {
  3445. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3446. {
  3447. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3448. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3449. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3450. {
  3451. //Reserved
  3452. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3453. }
  3454. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3455. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3456. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3457. {
  3458. //Reserved
  3459. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3460. result = FAIL;
  3461. goto end;
  3462. }
  3463. else
  3464. {
  3465. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3466. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3467. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3468. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3469. {
  3470. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3471. result = FAIL;
  3472. goto end;
  3473. }
  3474. }// END FOR ELSE
  3475. }
  3476. } // END FOR GB_QUANTITY
  3477. }
  3478. else
  3479. {
  3480. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3481. {
  3482. tempIndex = 2;
  3483. }
  3484. else
  3485. {
  3486. tempIndex = connectorIdInt -1;
  3487. }
  3488. for (int index = 0; index < AC_QUANTITY; index++)
  3489. {
  3490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3491. {
  3492. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3493. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3494. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3495. {
  3496. //Reserved
  3497. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3498. }
  3499. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3500. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3501. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3502. {
  3503. //Reserved
  3504. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3505. result = FAIL;
  3506. goto end;
  3507. }
  3508. else
  3509. {
  3510. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3511. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3512. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3513. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3514. {
  3515. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3516. result = FAIL;
  3517. goto end;
  3518. }
  3519. }//END FOR ELSE
  3520. }
  3521. }// END FOR AC_QUANTITY
  3522. }
  3523. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3524. {
  3525. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3526. {
  3527. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3528. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3529. {
  3530. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3531. system(cmdBuf);
  3532. }
  3533. }
  3534. else
  3535. {
  3536. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3537. result = FAIL;
  3538. }
  3539. }
  3540. end:
  3541. if(result == PASS)
  3542. {
  3543. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3544. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3545. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3546. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3548. }
  3549. }
  3550. void CheckSystemValue(void)
  3551. {
  3552. char filenmae[100]={0};
  3553. char str[100]={0};
  3554. int tempIndex = 0;
  3555. //===============================
  3556. // send Heartbeat
  3557. //===============================
  3558. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3559. {
  3560. //parameter for test
  3561. sendHeartbeatRequest(0);
  3562. //==============================================
  3563. // Reset Waiting Time
  3564. //==============================================
  3565. HeartBeatWithNOResponse += 2;
  3566. }
  3567. //===============================
  3568. // Credit deduct report
  3569. //===============================
  3570. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3571. {
  3572. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3573. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3574. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3575. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3576. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3577. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3578. }
  3579. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3580. {
  3581. OCPP_query_deduct_info();
  3582. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3583. }
  3584. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3585. {
  3586. // ClockAlign MeterValue
  3587. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3588. {
  3589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3590. {
  3591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3592. {
  3593. tempIndex = ((gun_index==2) ? 1: 0);
  3594. }
  3595. else
  3596. {
  3597. tempIndex = gun_index;
  3598. }
  3599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3600. {
  3601. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3603. {
  3604. reqClockAlignMeter[gun_index] = 1;
  3605. }
  3606. }// End for CHAdeMO
  3607. }
  3608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3609. {
  3610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3611. {
  3612. tempIndex = ((gun_index==2) ? 1: 0);
  3613. }
  3614. else
  3615. {
  3616. tempIndex = gun_index;
  3617. }
  3618. for (int index = 0; index < CCS_QUANTITY; index++)
  3619. {
  3620. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3621. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3622. {
  3623. reqClockAlignMeter[gun_index] = 1;
  3624. }
  3625. } // End for CCS
  3626. }
  3627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3628. {
  3629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3630. {
  3631. tempIndex = ((gun_index==2) ? 1: 0);
  3632. }
  3633. else
  3634. {
  3635. tempIndex = gun_index;
  3636. }
  3637. for (int index = 0; index < GB_QUANTITY; index++)
  3638. {
  3639. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3641. {
  3642. reqClockAlignMeter[gun_index] = 1;
  3643. }
  3644. }// End for GB
  3645. }
  3646. else if(gunType[gun_index] == GUN_TYPE_DO)
  3647. {
  3648. tempIndex = gun_index;
  3649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3650. {
  3651. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3652. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3653. {
  3654. reqClockAlignMeter[gun_index] = 1;
  3655. }
  3656. }
  3657. }
  3658. else
  3659. {
  3660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3661. {
  3662. tempIndex = 2;
  3663. }
  3664. else
  3665. {
  3666. tempIndex = gun_index;
  3667. }
  3668. for (int index = 0; index < AC_QUANTITY; index++)
  3669. {
  3670. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3671. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3672. {
  3673. reqClockAlignMeter[gun_index] = 1;
  3674. }
  3675. }//End for AC
  3676. }
  3677. }
  3678. }
  3679. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3680. {
  3681. //==========================================
  3682. // Check remote start without connector id
  3683. //==========================================
  3684. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3685. {
  3686. int connectorIdInt = -1;
  3687. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3688. {
  3689. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3690. {
  3691. connectorIdInt = (gun_index+1);
  3692. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3693. checkRemoteStart(connectorIdInt);
  3694. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3695. break;
  3696. }
  3697. }
  3698. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3699. {
  3700. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3701. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3702. }
  3703. }
  3704. //==========================================
  3705. // csu trigger DataTransferReq
  3706. //==========================================
  3707. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3708. {
  3709. sendDataTransferRequest(gun_index);
  3710. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3711. }
  3712. //===============================
  3713. // CSU Trigger Authorize Request
  3714. //===============================
  3715. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3716. {
  3717. sendAuthorizeRequest(0);
  3718. authorizeRetryTimes = authorizeRetryTimes + 1;
  3719. if(authorizeRetryTimes < 3)
  3720. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3721. }
  3722. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3723. {
  3724. authorizeRetryTimes = 0;
  3725. SetOcppConnStatus(FALSE);
  3726. server_sign = FALSE;
  3727. }
  3728. 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))
  3729. {
  3730. sendAuthorizeRequest(0);
  3731. }
  3732. //==============================================
  3733. // Charger start transaction
  3734. //==============================================
  3735. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3736. {
  3737. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3738. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3739. sendStartTransactionRequest(gun_index);
  3740. refreshStartTimer(&clientTime.StartTransaction);
  3741. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3742. //storeTempStopTransaction(gun_index);
  3743. }
  3744. //==============================================
  3745. // Charger stop transaction
  3746. //==============================================
  3747. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3748. {
  3749. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3750. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3751. sendStopTransactionRequest(gun_index);
  3752. refreshStartTimer(&clientTime.StopTransaction);
  3753. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3754. }
  3755. //==============================================
  3756. // Charger status report
  3757. //==============================================
  3758. //--- Check Mode Change ---//
  3759. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3760. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3761. {
  3762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3763. {
  3764. tempIndex = ((gun_index==2) ? 1: 0);
  3765. }
  3766. else
  3767. {
  3768. tempIndex = gun_index;
  3769. }
  3770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3771. {
  3772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3773. {
  3774. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3775. {
  3776. // Sent unplug message for California pricing logic
  3777. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3778. {
  3779. uint8_t ts[20];
  3780. getNowDatetime(ts);
  3781. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3782. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3783. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3784. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3785. }
  3786. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3787. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3788. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3789. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3790. {
  3791. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3792. if((access(filenmae,F_OK))!=-1)
  3793. {
  3794. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3795. sprintf(str,"rm -f %s",filenmae);
  3796. system(str);
  3797. }
  3798. }
  3799. }
  3800. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3801. #if 1 // for TempStopTransaction
  3802. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3803. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3804. {
  3805. checkTempStopTransaction(gun_index);
  3806. }
  3807. #endif
  3808. }
  3809. }
  3810. }
  3811. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3812. {
  3813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3814. {
  3815. tempIndex = ((gun_index==2) ? 1: 0);
  3816. }
  3817. else
  3818. {
  3819. tempIndex = gun_index;
  3820. }
  3821. for (int index = 0; index < CCS_QUANTITY; index++)
  3822. {
  3823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3824. {
  3825. 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]*/ )
  3826. {
  3827. // Sent unplug message for California pricing logic
  3828. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3829. {
  3830. uint8_t ts[20];
  3831. getNowDatetime(ts);
  3832. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3833. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3834. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3835. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3836. }
  3837. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3838. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3839. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3840. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3841. {
  3842. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3843. if((access(filenmae,F_OK))!=-1)
  3844. {
  3845. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3846. sprintf(str,"rm -f %s",filenmae);
  3847. system(str);
  3848. }
  3849. }
  3850. }
  3851. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3852. #if 1 // for TempStopTransaction
  3853. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3854. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3855. {
  3856. checkTempStopTransaction(gun_index);
  3857. }
  3858. #endif
  3859. }
  3860. }
  3861. }
  3862. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3863. {
  3864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3865. {
  3866. tempIndex = ((gun_index==2) ? 1: 0);
  3867. }
  3868. else
  3869. {
  3870. tempIndex = gun_index;
  3871. }
  3872. for (int index = 0; index < GB_QUANTITY; index++)
  3873. {
  3874. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3875. {
  3876. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3877. {
  3878. // Sent unplug message for California pricing logic
  3879. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3880. {
  3881. uint8_t ts[20];
  3882. getNowDatetime(ts);
  3883. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3884. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3885. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3886. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3887. }
  3888. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3889. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3891. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3892. {
  3893. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3894. if((access(filenmae,F_OK))!=-1)
  3895. {
  3896. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3897. sprintf(str,"rm -f %s",filenmae);
  3898. system(str);
  3899. }
  3900. }
  3901. }
  3902. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3903. #if 1 // for TempStopTransaction
  3904. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3905. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3906. {
  3907. checkTempStopTransaction(gun_index);
  3908. }
  3909. #endif
  3910. }
  3911. }
  3912. }
  3913. else if(gunType[gun_index] == GUN_TYPE_DO)
  3914. {
  3915. tempIndex = gun_index;
  3916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3917. {
  3918. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3919. {
  3920. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3921. {
  3922. // Sent unplug message for California pricing logic
  3923. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3924. {
  3925. uint8_t ts[20];
  3926. getNowDatetime(ts);
  3927. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3928. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3929. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3930. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3931. }
  3932. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3933. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3934. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3935. 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
  3936. {
  3937. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3938. if((access(filenmae,F_OK))!=-1)
  3939. {
  3940. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3941. sprintf(str,"rm -f %s",filenmae);
  3942. system(str);
  3943. }
  3944. }
  3945. }
  3946. 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);
  3947. #if 1 // for TempStopTransaction
  3948. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3949. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3950. {
  3951. checkTempStopTransaction(gun_index);
  3952. }
  3953. #endif
  3954. }
  3955. }
  3956. }
  3957. else
  3958. {
  3959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3960. {
  3961. tempIndex = 2;
  3962. }
  3963. else
  3964. {
  3965. tempIndex = gun_index;
  3966. }
  3967. for (int index = 0; index < AC_QUANTITY; index++)
  3968. {
  3969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3970. {
  3971. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3972. {
  3973. // Sent unplug message for California pricing logic
  3974. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3975. {
  3976. uint8_t ts[20];
  3977. getNowDatetime(ts);
  3978. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3979. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3980. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3981. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3982. }
  3983. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3984. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3985. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3986. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3987. {
  3988. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3989. if((access(filenmae,F_OK))!=-1)
  3990. {
  3991. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3992. sprintf(str,"rm -f %s",filenmae);
  3993. system(str);
  3994. }
  3995. }
  3996. }
  3997. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3998. #if 1 // for TempStopTransaction
  3999. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4000. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4001. {
  4002. checkTempStopTransaction(gun_index);
  4003. }
  4004. #endif
  4005. }
  4006. }// END
  4007. }
  4008. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4009. (
  4010. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4011. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4012. )
  4013. )
  4014. {
  4015. if(SystemInitial > 0)
  4016. SystemInitial -= 1;
  4017. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4018. sendStatusNotificationRequest(gun_index);
  4019. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4020. }
  4021. //==============================================
  4022. // CSU Trigger Smart Charging Profilw
  4023. //==============================================
  4024. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4025. {
  4026. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4027. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4028. }
  4029. //==============================================
  4030. // Meter report
  4031. //==============================================
  4032. // Trigger MeterValue
  4033. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4034. {
  4035. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4036. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4037. }
  4038. // Clock-aligned Meter value
  4039. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4040. {
  4041. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4042. reqClockAlignMeter[gun_index] = 0;
  4043. }
  4044. // Sample period MeterValue
  4045. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4046. {
  4047. //check Transaction active
  4048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4049. {
  4050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4051. {
  4052. tempIndex = ((gun_index==2) ? 1: 0);
  4053. }
  4054. else
  4055. {
  4056. tempIndex = gun_index;
  4057. }
  4058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4059. {
  4060. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4061. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4062. {
  4063. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4064. {
  4065. reqSampleMeter[gun_index] = 1;
  4066. }
  4067. }
  4068. }// End for CHAdeMO
  4069. }
  4070. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4071. {
  4072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4073. {
  4074. tempIndex = ((gun_index==2) ? 1: 0);
  4075. }
  4076. else
  4077. {
  4078. tempIndex = gun_index;
  4079. }
  4080. for (int index = 0; index < CCS_QUANTITY; index++)
  4081. {
  4082. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4083. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4084. {
  4085. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4086. {
  4087. reqSampleMeter[gun_index] = 1;
  4088. }
  4089. }
  4090. } // End for CCS
  4091. }
  4092. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4093. {
  4094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4095. {
  4096. tempIndex = ((gun_index==2) ? 1: 0);
  4097. }
  4098. else
  4099. {
  4100. tempIndex = gun_index;
  4101. }
  4102. for (int index = 0; index < GB_QUANTITY; index++)
  4103. {
  4104. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4105. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4106. {
  4107. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4108. {
  4109. reqSampleMeter[gun_index] = 1;
  4110. }
  4111. }
  4112. }// End for GB
  4113. }
  4114. else if(gunType[gun_index] == GUN_TYPE_DO)
  4115. {
  4116. tempIndex = gun_index;
  4117. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4118. {
  4119. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4120. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4121. {
  4122. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4123. {
  4124. reqSampleMeter[gun_index] = 1;
  4125. }
  4126. }
  4127. }
  4128. }
  4129. else
  4130. {
  4131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4132. {
  4133. tempIndex = 2;
  4134. }
  4135. else
  4136. {
  4137. tempIndex = gun_index;
  4138. }
  4139. for (int index = 0; index < AC_QUANTITY; index++)
  4140. {
  4141. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4142. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4143. {
  4144. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4145. {
  4146. reqSampleMeter[gun_index] = 1;
  4147. }
  4148. }
  4149. }//End for AC
  4150. }
  4151. if(reqSampleMeter[gun_index] == 1)
  4152. {
  4153. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4154. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4155. //storeTempStopTransaction(gun_index);
  4156. reqSampleMeter[gun_index] = 0;
  4157. }
  4158. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4159. }
  4160. //==============================================
  4161. // Check Connector reserved
  4162. //==============================================
  4163. //===============================
  4164. // Check if Reserve is expired
  4165. //===============================
  4166. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4167. {
  4168. double diff_t;
  4169. struct tm tp;
  4170. // current time
  4171. time_t t = time(NULL);
  4172. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4173. tp.tm_isdst = -1;
  4174. time_t utc = mktime(&tp);
  4175. diff_t = difftime(utc, t);
  4176. if(diff_t <= 0)
  4177. {
  4178. DEBUG_INFO("reserve expired.\n");
  4179. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4180. }
  4181. }//END OF Check if Reserve is expired
  4182. //==========================================
  4183. // csu trigger FirmwareStatusNotificationReq
  4184. //==========================================
  4185. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4186. {
  4187. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4188. }
  4189. //==========================================
  4190. // csu trigger DiagnosticsStatusNotificationReq
  4191. //==========================================
  4192. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4193. {
  4194. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4195. }
  4196. //==========================================
  4197. // csu trigger CancelReservationConf
  4198. //==========================================
  4199. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4200. {
  4201. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4202. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4203. }
  4204. //==========================================
  4205. // csu trigger ChangeAvailabilityConf
  4206. //==========================================
  4207. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4208. {
  4209. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4210. }
  4211. //==========================================
  4212. // csu trigger UnlockConnectorConf
  4213. //==========================================
  4214. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4215. {
  4216. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4217. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4218. }
  4219. //==========================================
  4220. // csu trigger ReserveNowConf
  4221. //==========================================
  4222. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4223. {
  4224. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4225. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4226. }
  4227. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4228. {
  4229. sendSignCertificateRequest();
  4230. }
  4231. }
  4232. }
  4233. //==========================================
  4234. // send request routine
  4235. //==========================================
  4236. int sendAuthorizeRequest(int gun_index)
  4237. {
  4238. mtrace();
  4239. int result = FAIL;
  4240. char message[100]={0};
  4241. char guid[37];
  4242. char tempdata[65]={0};
  4243. DEBUG_INFO("sendAuthorizeRequest...\n");
  4244. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4245. //Local Authorize
  4246. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4247. {
  4248. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4249. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4250. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4251. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4252. result = PASS;
  4253. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4254. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4255. authorizeRetryTimes = 0;
  4256. return result;
  4257. }
  4258. 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))||
  4259. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4260. {
  4261. // Query from cache
  4262. DEBUG_INFO("Authorize from cache.\n");
  4263. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4264. // Query from list
  4265. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4266. {
  4267. DEBUG_INFO("Authorize from list.\n");
  4268. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4269. }
  4270. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4271. {
  4272. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4273. {
  4274. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4275. }
  4276. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4277. {
  4278. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4279. }
  4280. if(!GetOcppConnStatus())
  4281. {
  4282. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4283. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4284. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4285. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4286. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4287. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4288. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4289. authorizeRetryTimes = 0;
  4290. return result;
  4291. }
  4292. }
  4293. else
  4294. {
  4295. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4296. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4297. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4298. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4299. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4300. else
  4301. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4302. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4303. result = PASS;
  4304. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4305. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4306. authorizeRetryTimes = 0;
  4307. return result;
  4308. }
  4309. }
  4310. //initialize struct Authorize
  4311. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4312. //get data from shared memory
  4313. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4314. random_uuid(guid);
  4315. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4316. LWS_Send(message);
  4317. sprintf(tempdata, "Authorize,%d", gun_index);
  4318. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4319. {
  4320. result = PASS;
  4321. DEBUG_INFO("Authorize mapItem pass\n");
  4322. }
  4323. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4324. return result;
  4325. }
  4326. int sendBootNotificationRequest(void)
  4327. {
  4328. mtrace();
  4329. int result = FAIL;
  4330. char message[500]={0}, payload[700]={0};
  4331. char guid[37]={0};
  4332. char tempdata[65]={0};
  4333. // Fill BootNotification fields
  4334. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4335. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4336. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4337. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4338. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4339. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4340. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4341. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4342. ShmOCPP16DataPH->ChargeBoxId
  4343. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4344. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4345. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4346. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4347. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4348. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4349. random_uuid(guid);
  4350. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4351. LWS_Send(message);
  4352. sprintf(tempdata, "BootNotification,0");
  4353. 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*/)
  4354. {
  4355. result = PASS;
  4356. }
  4357. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4358. strcpy(queuedata,message);
  4359. return result;
  4360. }
  4361. int sendDataTransferRequest(int gun_index)
  4362. {
  4363. mtrace();
  4364. char message[1000]={0};
  4365. char guid[37]={0};
  4366. char tempdata[65]={0};
  4367. int result = FAIL;
  4368. random_uuid(guid);
  4369. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4370. MESSAGE_TYPE_CALL,
  4371. guid,
  4372. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4373. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4374. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4375. LWS_Send(message);
  4376. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4377. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4378. {
  4379. result = PASS;
  4380. DEBUG_INFO("DataTransfer mapItem pass\n");
  4381. }
  4382. return result;
  4383. }
  4384. int sendDiagnosticsStatusNotificationRequest(char *status)
  4385. {
  4386. mtrace();
  4387. int result = FAIL;
  4388. char message[110]={0};
  4389. char guid[37]={0};
  4390. char tempdata[65]={0};
  4391. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4392. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4393. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4394. random_uuid(guid);
  4395. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4396. LWS_SendNow(message);
  4397. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4398. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4399. {
  4400. result = PASS;
  4401. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4402. }
  4403. //#ifdef SystemLogMessage
  4404. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4405. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4406. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4407. //#endif
  4408. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4409. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4410. //record status
  4411. if(strcmp(status,"Idle")==0)
  4412. {
  4413. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4414. }
  4415. else if(strcmp(status,"Uploaded")==0)
  4416. {
  4417. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4418. }
  4419. else if(strcmp(status,"UploadFailed")==0)
  4420. {
  4421. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4422. }
  4423. else if(strcmp(status,"Uploading")==0)
  4424. {
  4425. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4426. }
  4427. return result;
  4428. }
  4429. int sendFirmwareStatusNotificationRequest(char *status)
  4430. {
  4431. mtrace();
  4432. int result = FAIL;
  4433. char message[110]={0};
  4434. char guid[37]={0};
  4435. char tempdata[65]={0};
  4436. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4437. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4438. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4439. random_uuid(guid);
  4440. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4441. LWS_SendNow(message);
  4442. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4443. 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*/)
  4444. {
  4445. result = PASS;
  4446. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4447. }
  4448. //#ifdef SystemLogMessage
  4449. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4450. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4451. //#endif
  4452. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4453. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4454. //record status
  4455. if(strcmp(status,"Downloaded")==0)
  4456. {
  4457. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4458. }
  4459. else if(strcmp(status,"DownloadFailed")==0)
  4460. {
  4461. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4462. }
  4463. else if(strcmp(status,"Downloading")==0)
  4464. {
  4465. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4466. }
  4467. else if(strcmp(status,"Idle")==0)
  4468. {
  4469. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4470. }
  4471. else if(strcmp(status,"InstallationFailed")==0)
  4472. {
  4473. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4474. }
  4475. else if(strcmp(status,"Installing")==0)
  4476. {
  4477. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4478. }
  4479. else if(strcmp(status,"Installed")==0)
  4480. {
  4481. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4482. }
  4483. return result;
  4484. }
  4485. int sendHeartbeatRequest(int gun_index)
  4486. {
  4487. mtrace();
  4488. int result = FAIL;
  4489. char message[80]={0};
  4490. char guid[37]={0};
  4491. char tempdata[65]={0};
  4492. random_uuid(guid);
  4493. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4494. , MESSAGE_TYPE_CALL
  4495. , guid );
  4496. LWS_Send(message);
  4497. sprintf(tempdata, "Heartbeat,%d", 0);
  4498. 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*/)
  4499. {
  4500. result = PASS;
  4501. }
  4502. return result;
  4503. }
  4504. int sendStartTransactionRequest(int gun_index)
  4505. {
  4506. mtrace();
  4507. int result = FAIL;
  4508. char message[250]={0};
  4509. char guid[37]={0};
  4510. struct timeval tmnow;
  4511. struct tm *tm;
  4512. char buf[28];//, usec_buf[6];
  4513. char tempdata[65]={0};
  4514. int tempIndex = 0;
  4515. DEBUG_INFO("sendStartTransactionRequest...\n");
  4516. gettimeofday(&tmnow, NULL);
  4517. time_t t;
  4518. t = time(NULL);
  4519. /*UTC time and date*/
  4520. tm = gmtime(&t);
  4521. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4522. #if 0 // remove temporally
  4523. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4524. strcat(buf,".");
  4525. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4526. strcat(buf,usec_buf);
  4527. #endif
  4528. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4529. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4530. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4531. // clear StartTransaction Response
  4532. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4533. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4534. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4535. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4536. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4537. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4538. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4539. {
  4540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4541. {
  4542. tempIndex = ((gun_index==2) ? 1: 0);
  4543. }
  4544. else
  4545. {
  4546. tempIndex = gun_index;
  4547. }
  4548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4549. {
  4550. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4551. {
  4552. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4553. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4554. }
  4555. }
  4556. }
  4557. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4558. {
  4559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4560. {
  4561. tempIndex = ((gun_index==2) ? 1: 0);
  4562. }
  4563. else
  4564. {
  4565. tempIndex = gun_index;
  4566. }
  4567. for (int index = 0; index < CCS_QUANTITY; index++)
  4568. {
  4569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4570. {
  4571. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4572. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4573. }
  4574. }
  4575. }
  4576. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4577. {
  4578. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4579. {
  4580. tempIndex = ((gun_index==2) ? 1: 0);
  4581. }
  4582. else
  4583. {
  4584. tempIndex = gun_index;
  4585. }
  4586. for (int index = 0; index < GB_QUANTITY; index++)
  4587. {
  4588. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4589. {
  4590. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4591. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4592. }
  4593. }
  4594. }
  4595. else if(gunType[gun_index] == GUN_TYPE_DO)
  4596. {
  4597. tempIndex = gun_index;
  4598. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4601. {
  4602. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4603. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4604. }
  4605. }
  4606. }
  4607. else
  4608. {
  4609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4610. {
  4611. tempIndex = 2;
  4612. }
  4613. else
  4614. {
  4615. tempIndex = gun_index;
  4616. }
  4617. for (int index = 0; index < AC_QUANTITY; index++)
  4618. {
  4619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4620. {
  4621. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4622. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4623. }
  4624. }
  4625. }
  4626. random_uuid(guid);
  4627. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4628. {
  4629. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4630. , gun_index +1
  4631. , MESSAGE_TYPE_CALL
  4632. , guid
  4633. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4634. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4635. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4636. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4637. }
  4638. else
  4639. {
  4640. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4641. , gun_index +1
  4642. , MESSAGE_TYPE_CALL
  4643. , guid
  4644. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4645. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4646. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4647. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4648. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4649. }
  4650. #if 1
  4651. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4652. 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*/)
  4653. {
  4654. result = PASS;
  4655. }
  4656. #endif
  4657. strcpy(queuedata, message);
  4658. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4659. OCPP_insert_transaction_msg(YES, queuedata);
  4660. return result;
  4661. }
  4662. int sendStatusNotificationRequest(int gun_index)
  4663. {
  4664. mtrace();
  4665. int result = FAIL;
  4666. char message[600]={0};
  4667. char guid[37];
  4668. int currentStatus = 0;
  4669. struct timeval tmnow;
  4670. struct tm *tm;
  4671. char buf[28];//, usec_buf[6];
  4672. char tempdata[65]={0};
  4673. int tempIndex = 0;
  4674. uint8_t isStateChanged = TRUE;
  4675. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4676. gettimeofday(&tmnow, NULL);
  4677. time_t t;
  4678. t = time(NULL);
  4679. /*UTC time and date*/
  4680. tm = gmtime(&t);
  4681. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4682. #if 0 // remove temporally
  4683. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4684. strcat(buf,".");
  4685. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4686. strcat(buf,usec_buf);
  4687. #endif
  4688. //printf("%s",buf);
  4689. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4690. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4691. // it's option
  4692. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4693. /*
  4694. enum _SYSTEM_STATUS
  4695. {
  4696. S_BOOTING = 0,
  4697. S_IDLE, = 1
  4698. S_AUTHORIZING, =2
  4699. S_REASSIGN_CHECK, =3
  4700. S_REASSIGN, =4
  4701. S_PRECHARGE, =5
  4702. S_PREPARING_FOR_EV, =6
  4703. S_PREPARING_FOR_EVSE, =7
  4704. S_CHARGING, =8
  4705. S_TERMINATING, =9
  4706. S_COMPLETE, =10
  4707. S_ALARM, =11
  4708. S_FAULT =12
  4709. }
  4710. */
  4711. //check Transaction active
  4712. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4713. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4714. {
  4715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4716. {
  4717. tempIndex = ((gun_index==2) ? 1: 0);
  4718. }
  4719. else
  4720. {
  4721. tempIndex = gun_index;
  4722. }
  4723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4724. {
  4725. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4726. {
  4727. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4728. {
  4729. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4730. {
  4731. currentStatus = Preparing; //OCPP Status: Preparing
  4732. }
  4733. else
  4734. {
  4735. currentStatus = Available; //OCPP Status: Available
  4736. }
  4737. }
  4738. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4739. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4740. ) //S_PRECHARGE
  4741. {
  4742. currentStatus = Preparing; //OCPP Status: Preparing
  4743. }
  4744. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4745. {
  4746. currentStatus = Charging; //OCPP Status: Charging
  4747. }
  4748. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4749. {
  4750. currentStatus = Finishing; //OCPP Status: Finishing
  4751. }
  4752. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4753. {
  4754. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4755. }
  4756. 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
  4757. {
  4758. currentStatus = Unavailable; //OCPP Status: Unavailable
  4759. }
  4760. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4761. {
  4762. currentStatus = Faulted; //OCPP Status: Faulted
  4763. }
  4764. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4765. {
  4766. currentStatus = Reserved; //OCPP Status: Reserved
  4767. }
  4768. } //end of the same index
  4769. }//end of for CHAdeMO_QUANTITY
  4770. }
  4771. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4772. {
  4773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4774. {
  4775. tempIndex = ((gun_index==2) ? 1: 0);
  4776. }
  4777. else
  4778. {
  4779. tempIndex = gun_index;
  4780. }
  4781. for (int index = 0; index < CCS_QUANTITY; index++)
  4782. {
  4783. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4784. {
  4785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4786. {
  4787. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4788. {
  4789. currentStatus = Preparing; //OCPP Status: Preparing
  4790. }
  4791. else
  4792. {
  4793. currentStatus = Available; //OCPP Status: Available
  4794. }
  4795. }
  4796. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4797. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4798. ) //S_PRECHARGE
  4799. {
  4800. currentStatus = Preparing; //OCPP Status: Preparing
  4801. }
  4802. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4803. {
  4804. currentStatus = Charging; //OCPP Status: Charging
  4805. }
  4806. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4807. {
  4808. currentStatus = Finishing; //OCPP Status: Finishing
  4809. }
  4810. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4811. {
  4812. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4813. }
  4814. 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
  4815. {
  4816. currentStatus = Unavailable; //OCPP Status : Unavailable
  4817. }
  4818. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4819. {
  4820. currentStatus = Faulted; //OCPP Status: Faulted
  4821. }
  4822. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4823. {
  4824. currentStatus = Reserved; //OCPP Status: Reserved
  4825. }
  4826. } //end of the same index
  4827. } // end of for CCS_QUANTITY
  4828. }
  4829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4832. {
  4833. tempIndex = ((gun_index==2) ? 1: 0);
  4834. }
  4835. else
  4836. {
  4837. tempIndex = gun_index;
  4838. }
  4839. for (int index = 0; index < GB_QUANTITY; index++)
  4840. {
  4841. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4842. {
  4843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4844. {
  4845. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4846. {
  4847. currentStatus = Preparing; //OCPP Status: Preparing
  4848. }
  4849. else
  4850. {
  4851. currentStatus = Available; //OCPP Status: Available
  4852. }
  4853. }
  4854. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4855. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4856. ) //S_PRECHARGE
  4857. {
  4858. currentStatus = Preparing; //OCPP Status: Preparing
  4859. }
  4860. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4861. {
  4862. currentStatus = Charging; //OCPP Status: Charging
  4863. }
  4864. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4865. {
  4866. currentStatus = Finishing; //OCPP Status: Finishing
  4867. }
  4868. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4869. {
  4870. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4871. }
  4872. 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
  4873. {
  4874. currentStatus = Unavailable; //OCPP Status: Unavailable
  4875. }
  4876. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4877. {
  4878. currentStatus = Faulted; //OCPP Status: Faulted
  4879. }
  4880. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4881. {
  4882. currentStatus = Reserved; //OCPP Status: Reserved
  4883. }
  4884. } //end of the same index
  4885. } // end of for GB_QUANTITY
  4886. }
  4887. else if(gunType[gun_index] == GUN_TYPE_DO)
  4888. {
  4889. tempIndex = gun_index;
  4890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4891. {
  4892. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4893. {
  4894. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4895. {
  4896. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4897. {
  4898. currentStatus = Preparing; //OCPP Status: Preparing
  4899. }
  4900. else
  4901. {
  4902. currentStatus = Available; //OCPP Status: Available
  4903. }
  4904. }
  4905. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4906. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4907. ) //S_PRECHARGE
  4908. {
  4909. currentStatus = Preparing; //OCPP Status: Preparing
  4910. }
  4911. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4912. {
  4913. currentStatus = Charging; //OCPP Status: Charging
  4914. }
  4915. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4916. {
  4917. currentStatus = Finishing; //OCPP Status: Finishing
  4918. }
  4919. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4920. {
  4921. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4922. }
  4923. 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
  4924. {
  4925. currentStatus = Unavailable; //OCPP Status: Unavailable
  4926. }
  4927. 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
  4928. {
  4929. currentStatus = Faulted; //OCPP Status: Faulted
  4930. }
  4931. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4932. {
  4933. currentStatus = Reserved; //OCPP Status: Reserved
  4934. }
  4935. } //end of the same index
  4936. }
  4937. }
  4938. else
  4939. {
  4940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4941. {
  4942. tempIndex = 2;
  4943. }
  4944. else
  4945. {
  4946. tempIndex = gun_index;
  4947. }
  4948. for (int index = 0; index < AC_QUANTITY; index++)
  4949. {
  4950. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4951. {
  4952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4953. {
  4954. 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))
  4955. {
  4956. currentStatus = Preparing; //OCPP Status: Preparing
  4957. }
  4958. else
  4959. {
  4960. currentStatus = Available; //OCPP Status: Available
  4961. }
  4962. }
  4963. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4964. {
  4965. currentStatus = Preparing; //OCPP Status: Preparing
  4966. }
  4967. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4968. {
  4969. currentStatus = Charging; //OCPP Status: Charging
  4970. }
  4971. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4972. {
  4973. currentStatus = Finishing; //OCPP Status: Finishing
  4974. }
  4975. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4976. {
  4977. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4978. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4979. else
  4980. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4981. }
  4982. 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
  4983. {
  4984. currentStatus = Unavailable; //OCPP Status: Unavailable
  4985. }
  4986. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4987. {
  4988. currentStatus = Faulted; //OCPP Status: Faulted
  4989. }
  4990. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4991. {
  4992. currentStatus = Reserved; //OCPP Status: Reserved
  4993. }
  4994. }//end of the same index
  4995. }//end of for AC_QUANTITY
  4996. }
  4997. //it's option
  4998. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4999. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5000. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5001. {
  5002. isStateChanged = FALSE;
  5003. }
  5004. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5005. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5006. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5007. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5008. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5009. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5010. random_uuid(guid);
  5011. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5012. , MESSAGE_TYPE_CALL
  5013. , guid
  5014. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5015. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5016. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5017. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5018. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5019. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5020. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5021. if((server_sign == TRUE) && isStateChanged)
  5022. {
  5023. LWS_Send(message);
  5024. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5025. 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*/)
  5026. {
  5027. //DEBUG_ERROR("statusNotification mapitem pass");
  5028. result = PASS;
  5029. }
  5030. }
  5031. else
  5032. {
  5033. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5034. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5035. result = PASS;
  5036. }
  5037. return result;
  5038. }
  5039. int sendStopTransactionRequest(int gun_index)
  5040. {
  5041. mtrace();
  5042. int result = FAIL;
  5043. //char message[1500]={0};
  5044. char guid[37]={0};
  5045. char tempdata[65]={0};
  5046. int tempIndex = 0;
  5047. char TempStopTransaction[256];
  5048. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5049. //int idx_sample=0;
  5050. DEBUG_INFO("sendStopTransactionRequest \n");
  5051. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5052. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5053. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5054. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5055. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5056. {
  5057. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5058. {
  5059. tempIndex = ((gun_index==2) ? 1: 0);
  5060. }
  5061. else
  5062. {
  5063. tempIndex = gun_index;
  5064. }
  5065. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5066. {
  5067. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5068. {
  5069. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5070. }
  5071. }// END OF CHAdeMO_QUANTITY
  5072. }
  5073. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5074. {
  5075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5076. {
  5077. tempIndex = ((gun_index==2) ? 1: 0);
  5078. }
  5079. else
  5080. {
  5081. tempIndex = gun_index;
  5082. }
  5083. for (int index = 0; index < CCS_QUANTITY; index++)
  5084. {
  5085. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5086. {
  5087. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5088. }
  5089. }// END OF CCS_QUANTITY
  5090. }
  5091. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5092. {
  5093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5094. {
  5095. tempIndex = ((gun_index==2) ? 1: 0);
  5096. }
  5097. else
  5098. {
  5099. tempIndex = gun_index;
  5100. }
  5101. for (int index = 0; index < GB_QUANTITY; index++)
  5102. {
  5103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5104. {
  5105. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5106. }
  5107. }// END OF GB_QUANTITY
  5108. }
  5109. else if(gunType[gun_index] == GUN_TYPE_DO)
  5110. {
  5111. tempIndex = gun_index;
  5112. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5113. {
  5114. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5115. {
  5116. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5117. }
  5118. }// END OF GB_QUANTITY
  5119. }
  5120. else
  5121. {
  5122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5123. {
  5124. tempIndex = 2;
  5125. }
  5126. else
  5127. {
  5128. tempIndex = gun_index;
  5129. }
  5130. for (int index = 0; index < AC_QUANTITY; index++)
  5131. {
  5132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5133. {
  5134. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5135. }
  5136. }// END OF AC_QUANTITY
  5137. }
  5138. //====================================== Stop Transaction Time =====================================================
  5139. struct timeval tmnow;
  5140. struct tm *tm;
  5141. char buf[28];//, usec_buf[6];
  5142. gettimeofday(&tmnow, NULL);
  5143. time_t t;
  5144. t = time(NULL);
  5145. /*UTC time and date*/
  5146. tm = gmtime(&t);
  5147. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5149. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5150. random_uuid(guid);
  5151. /***********************************transactionData******************************************************/
  5152. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5154. //=================================
  5155. // Transaction_Begin
  5156. //=================================
  5157. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5158. {
  5159. //============================================ Energy.Active.Import.Interval ================================
  5160. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5163. 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*/]);
  5164. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5165. 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))
  5166. {
  5167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5168. }
  5169. else
  5170. {
  5171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5172. }
  5173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5175. }
  5176. //=================================
  5177. // Transaction_End
  5178. //=================================
  5179. // ================================= Current.Import L1 ===============================================
  5180. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5181. {
  5182. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5183. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5184. {
  5185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5186. {
  5187. tempIndex = ((gun_index==2) ? 1: 0);
  5188. }
  5189. else
  5190. {
  5191. tempIndex = gun_index;
  5192. }
  5193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5196. {
  5197. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5198. }
  5199. }// End of for CHAdeMO_QUANTITY
  5200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5201. }
  5202. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5203. {
  5204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5205. {
  5206. tempIndex = ((gun_index==2) ? 1: 0);
  5207. }
  5208. else
  5209. {
  5210. tempIndex = gun_index;
  5211. }
  5212. for (int index = 0; index < CCS_QUANTITY; index++)
  5213. {
  5214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5215. {
  5216. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5217. }
  5218. }// End of for CCS_QUANTITY
  5219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5220. }
  5221. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5222. {
  5223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5224. {
  5225. tempIndex = ((gun_index==2) ? 1: 0);
  5226. }
  5227. else
  5228. {
  5229. tempIndex = gun_index;
  5230. }
  5231. for (int index = 0; index < GB_QUANTITY; index++)
  5232. {
  5233. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5234. {
  5235. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5236. }
  5237. }// End of for GB_QUANTITY
  5238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5239. }
  5240. else if(gunType[gun_index] == GUN_TYPE_DO)
  5241. {
  5242. tempIndex = gun_index;
  5243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5248. }
  5249. }
  5250. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5251. }
  5252. else
  5253. {
  5254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5255. {
  5256. tempIndex = 2;
  5257. }
  5258. else
  5259. {
  5260. tempIndex = gun_index;
  5261. }
  5262. for (int index = 0; index < AC_QUANTITY; index++)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5265. {
  5266. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5267. }
  5268. }// End of for AC_QUANTITY
  5269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5270. }
  5271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5276. }
  5277. // ================================= Energy.Active.Import.Interval ==============================================
  5278. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5279. {
  5280. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5281. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5282. {
  5283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5284. {
  5285. tempIndex = ((gun_index==2) ? 1: 0);
  5286. }
  5287. else
  5288. {
  5289. tempIndex = gun_index;
  5290. }
  5291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5292. {
  5293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5294. {
  5295. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5296. }
  5297. }// END OF CHAdeMO_QUANTITY
  5298. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5299. }
  5300. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5301. {
  5302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5303. {
  5304. tempIndex = ((gun_index==2) ? 1: 0);
  5305. }
  5306. else
  5307. {
  5308. tempIndex = gun_index;
  5309. }
  5310. for (int index = 0; index < CCS_QUANTITY; index++)
  5311. {
  5312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5313. {
  5314. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5315. }
  5316. }// END OF CCS_QUANTITY
  5317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5318. }
  5319. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5320. {
  5321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5322. {
  5323. tempIndex = ((gun_index==2) ? 1: 0);
  5324. }
  5325. else
  5326. {
  5327. tempIndex = gun_index;
  5328. }
  5329. for (int index = 0; index < GB_QUANTITY; index++)
  5330. {
  5331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5332. {
  5333. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5334. }
  5335. }// END OF GB_QUANTITY
  5336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5337. }
  5338. else if(gunType[gun_index] == GUN_TYPE_DO)
  5339. {
  5340. tempIndex = gun_index;
  5341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5342. {
  5343. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5344. {
  5345. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5346. }
  5347. }
  5348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5349. }
  5350. else
  5351. {
  5352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5353. {
  5354. tempIndex = 2;
  5355. }
  5356. else
  5357. {
  5358. tempIndex = gun_index;
  5359. }
  5360. for (int index = 0; index < AC_QUANTITY; index++)
  5361. {
  5362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5363. {
  5364. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5365. }
  5366. }// END OF AC_QUANTITY
  5367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5368. }
  5369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5370. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5372. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5373. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5374. }
  5375. //=================================== Power.Active.Import ==================================================
  5376. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5377. {
  5378. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5380. {
  5381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5382. {
  5383. tempIndex = ((gun_index==2) ? 1: 0);
  5384. }
  5385. else
  5386. {
  5387. tempIndex = gun_index;
  5388. }
  5389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5390. {
  5391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5392. {
  5393. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5394. }
  5395. } // End for CHAdeMO_QUANTITY
  5396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5397. }
  5398. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5399. {
  5400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5401. {
  5402. tempIndex = ((gun_index==2) ? 1: 0);
  5403. }
  5404. else
  5405. {
  5406. tempIndex = gun_index;
  5407. }
  5408. for (int index = 0; index < CCS_QUANTITY; index++)
  5409. {
  5410. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5411. {
  5412. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5413. }
  5414. } // END for CCS_QUANTITY
  5415. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5416. }
  5417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5418. {
  5419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5420. {
  5421. tempIndex = ((gun_index==2) ? 1: 0);
  5422. }
  5423. else
  5424. {
  5425. tempIndex = gun_index;
  5426. }
  5427. for (int index = 0; index < GB_QUANTITY; index++)
  5428. {
  5429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5430. {
  5431. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5432. }
  5433. }// END for GB_QUANTITY
  5434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5435. }
  5436. else if(gunType[gun_index] == GUN_TYPE_DO)
  5437. {
  5438. tempIndex = gun_index;
  5439. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5440. {
  5441. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5442. {
  5443. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5444. }
  5445. }
  5446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5447. }
  5448. else
  5449. {
  5450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5451. {
  5452. tempIndex = 2;
  5453. }
  5454. else
  5455. {
  5456. tempIndex = gun_index;
  5457. }
  5458. for (int index = 0; index < AC_QUANTITY; index++)
  5459. {
  5460. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5461. {
  5462. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5463. }
  5464. } // END for AC_QUANTITY
  5465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5466. }
  5467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5468. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5470. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5471. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5472. }
  5473. //============================ Voltage L1 ====================================
  5474. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5475. {
  5476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5477. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5478. {
  5479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5480. {
  5481. tempIndex = ((gun_index==2) ? 1: 0);
  5482. }
  5483. else
  5484. {
  5485. tempIndex = gun_index;
  5486. }
  5487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5488. {
  5489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5490. {
  5491. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5492. }
  5493. } // END OF FOR CHAdeMO_QUANTITY
  5494. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5495. }
  5496. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5497. {
  5498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5499. {
  5500. tempIndex = ((gun_index==2) ? 1: 0);
  5501. }
  5502. else
  5503. {
  5504. tempIndex = gun_index;
  5505. }
  5506. for (int index = 0; index < CCS_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5511. }
  5512. } // END OF FOR CCS_QUANTITY
  5513. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5514. }
  5515. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5516. {
  5517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5518. {
  5519. tempIndex = ((gun_index==2) ? 1: 0);
  5520. }
  5521. else
  5522. {
  5523. tempIndex = gun_index;
  5524. }
  5525. for (int index = 0; index < GB_QUANTITY; index++)
  5526. {
  5527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5528. {
  5529. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5530. }
  5531. } // END OF FOR GB_QUANTITY
  5532. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5533. }
  5534. else if(gunType[gun_index] == GUN_TYPE_DO)
  5535. {
  5536. tempIndex = gun_index;
  5537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5538. {
  5539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5540. {
  5541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5542. }
  5543. }
  5544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5545. }
  5546. else
  5547. {
  5548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5549. {
  5550. tempIndex = 2;
  5551. }
  5552. else
  5553. {
  5554. tempIndex = gun_index;
  5555. }
  5556. for (int index = 0; index < AC_QUANTITY; index++)
  5557. {
  5558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5559. {
  5560. 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
  5561. }
  5562. } // END OF FOR AC_QUANTITY
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5564. }
  5565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5570. }
  5571. //====================== End SoC ================================
  5572. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5573. {
  5574. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5575. 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))
  5576. {
  5577. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5578. {
  5579. tempIndex = ((gun_index==2) ? 1: 0);
  5580. }
  5581. else
  5582. {
  5583. tempIndex = gun_index;
  5584. }
  5585. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5586. {
  5587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5588. {
  5589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5590. {
  5591. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5592. }
  5593. }
  5594. }
  5595. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5596. {
  5597. for (int index = 0; index < CCS_QUANTITY; index++)
  5598. {
  5599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5600. {
  5601. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5602. }
  5603. }
  5604. }
  5605. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5606. {
  5607. for (int index = 0; index < GB_QUANTITY; index++)
  5608. {
  5609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5610. {
  5611. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5612. }
  5613. }
  5614. }
  5615. else if(gunType[gun_index] == GUN_TYPE_DO)
  5616. {
  5617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5618. {
  5619. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5620. {
  5621. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5622. }
  5623. }
  5624. }
  5625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5631. } // END FOR DC CASE
  5632. }
  5633. // ================================= Current.Import L2 ===============================================
  5634. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5635. {
  5636. // AC 3 phse L2 current
  5637. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5638. {
  5639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5640. {
  5641. tempIndex = 2;
  5642. }
  5643. else
  5644. {
  5645. tempIndex = gun_index;
  5646. }
  5647. for (int index = 0; index < AC_QUANTITY; index++)
  5648. {
  5649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5650. {
  5651. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5652. }
  5653. }// End of for AC_QUANTITY
  5654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5655. }
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5661. }
  5662. // ================================= Current.Import L3 ===============================================
  5663. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5664. {
  5665. // AC 3 phse L3 current
  5666. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5667. {
  5668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5669. {
  5670. tempIndex = 2;
  5671. }
  5672. else
  5673. {
  5674. tempIndex = gun_index;
  5675. }
  5676. for (int index = 0; index < AC_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5681. }
  5682. }// End of for AC_QUANTITY
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5684. }
  5685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5688. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5690. }
  5691. //============================ Voltage L2 ====================================
  5692. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5693. {
  5694. // AC 3 phse L2 voltage
  5695. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5696. {
  5697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5698. {
  5699. tempIndex = 2;
  5700. }
  5701. else
  5702. {
  5703. tempIndex = gun_index;
  5704. }
  5705. for (int index = 0; index < AC_QUANTITY; index++)
  5706. {
  5707. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5708. {
  5709. 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
  5710. }
  5711. } // END OF FOR AC_QUANTITY
  5712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5713. }
  5714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5719. }
  5720. //============================ Voltage L3 ====================================
  5721. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5722. {
  5723. // AC 3 phse L3 voltage
  5724. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5725. {
  5726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5727. {
  5728. tempIndex = 2;
  5729. }
  5730. else
  5731. {
  5732. tempIndex = gun_index;
  5733. }
  5734. for (int index = 0; index < AC_QUANTITY; index++)
  5735. {
  5736. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5737. {
  5738. 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
  5739. }
  5740. } // END OF FOR AC_QUANTITY
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5742. }
  5743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5748. }
  5749. //====================== Start SoC ================================
  5750. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5751. {
  5752. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5753. 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))
  5754. {
  5755. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5756. {
  5757. tempIndex = ((gun_index==2) ? 1: 0);
  5758. }
  5759. else
  5760. {
  5761. tempIndex = gun_index;
  5762. }
  5763. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5764. {
  5765. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5768. {
  5769. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5770. }
  5771. }
  5772. }
  5773. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5774. {
  5775. for (int index = 0; index < CCS_QUANTITY; index++)
  5776. {
  5777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5778. {
  5779. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5780. }
  5781. }
  5782. }
  5783. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5784. {
  5785. for (int index = 0; index < GB_QUANTITY; index++)
  5786. {
  5787. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5788. {
  5789. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5790. }
  5791. }
  5792. }
  5793. else if(gunType[gun_index] == GUN_TYPE_DO)
  5794. {
  5795. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5796. {
  5797. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5798. {
  5799. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5800. }
  5801. }
  5802. }
  5803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5809. } // END FOR DC CASE
  5810. }
  5811. //================================================ Message create ====================================================
  5812. json_object *StopTransaction = json_object_new_object();
  5813. json_object *transactionDatas = json_object_new_array();
  5814. json_object *sampledValues = json_object_new_array();
  5815. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5816. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5817. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5818. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5819. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5820. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5821. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5822. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5823. {
  5824. json_object *transactionData = json_object_new_object();
  5825. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5826. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5827. {
  5828. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5829. {
  5830. json_object *sampledValue = json_object_new_object();
  5831. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5832. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5833. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5834. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5835. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5836. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5837. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5838. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5839. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5840. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5841. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5842. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5843. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5844. json_object_array_add(sampledValues, sampledValue);
  5845. }
  5846. }
  5847. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5848. json_object_array_add(transactionDatas, transactionData);
  5849. }
  5850. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5851. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5852. ,MESSAGE_TYPE_CALL
  5853. ,guid
  5854. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5855. json_object_put(StopTransaction);
  5856. #if 1 // for TempStopTransaction
  5857. //Delete TempStopTransaction
  5858. if((access(TempStopTransaction,F_OK))!=-1)
  5859. {
  5860. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5861. }
  5862. #endif
  5863. #if 1
  5864. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5865. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5866. {
  5867. result = PASS;
  5868. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5869. }
  5870. #endif
  5871. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5872. OCPP_insert_transaction_msg(NO, queuedata);
  5873. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5874. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5875. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5876. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5877. {
  5878. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5879. }
  5880. //for test
  5881. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5882. return result;
  5883. }
  5884. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5885. {
  5886. mtrace();
  5887. int result = FAIL;
  5888. char guid[37]={0};
  5889. char tempdata[65]={0};
  5890. int tempIndex = 0;
  5891. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5892. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5893. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5894. //set value
  5895. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5896. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5897. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5898. -1);
  5899. random_uuid(guid);
  5900. //UTC Date time
  5901. struct timeval tmnow;
  5902. struct tm *tm;
  5903. char buf[28];//, usec_buf[6];
  5904. gettimeofday(&tmnow, NULL);
  5905. time_t t;
  5906. t = time(NULL);
  5907. /*UTC time and date*/
  5908. tm = gmtime(&t);
  5909. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5910. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5911. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5912. //********************************(1)Current.Import L1************************************************/
  5913. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5914. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5915. (dataType == ReadingContext_Trigger))
  5916. {
  5917. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5918. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5919. {
  5920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5921. {
  5922. tempIndex = ((gun_index==2) ? 1: 0);
  5923. }
  5924. else
  5925. {
  5926. tempIndex = gun_index;
  5927. }
  5928. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5931. {
  5932. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5933. }
  5934. }
  5935. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5936. }
  5937. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5938. {
  5939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5940. {
  5941. tempIndex = ((gun_index==2) ? 1: 0);
  5942. }
  5943. else
  5944. {
  5945. tempIndex = gun_index;
  5946. }
  5947. for (int index = 0; index < CCS_QUANTITY; index++)
  5948. {
  5949. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5950. {
  5951. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5952. }
  5953. }
  5954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5955. }
  5956. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5957. {
  5958. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5959. {
  5960. tempIndex = ((gun_index==2) ? 1: 0);
  5961. }
  5962. else
  5963. {
  5964. tempIndex = gun_index;
  5965. }
  5966. for (int index = 0; index < GB_QUANTITY; index++)
  5967. {
  5968. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5969. {
  5970. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5971. }
  5972. }
  5973. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5974. }
  5975. else if(gunType[gun_index] == GUN_TYPE_DO)
  5976. {
  5977. tempIndex = gun_index;
  5978. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5983. }
  5984. }
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5986. }
  5987. else
  5988. {
  5989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5990. {
  5991. tempIndex = 2;
  5992. }
  5993. else
  5994. {
  5995. tempIndex = gun_index;
  5996. }
  5997. for (int index = 0; index < AC_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6000. {
  6001. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6002. }
  6003. }
  6004. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6005. }
  6006. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6007. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6008. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6009. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6010. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6011. }
  6012. //********************************(2)Energy.Active.Import.Register ************************************************/
  6013. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6014. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6015. (dataType == ReadingContext_Trigger))
  6016. {
  6017. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6018. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6019. {
  6020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6021. {
  6022. tempIndex = ((gun_index==2) ? 1: 0);
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6029. {
  6030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6031. {
  6032. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6033. }
  6034. }
  6035. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6036. }
  6037. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6038. {
  6039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6040. {
  6041. tempIndex = ((gun_index==2) ? 1: 0);
  6042. }
  6043. else
  6044. {
  6045. tempIndex = gun_index;
  6046. }
  6047. for (int index = 0; index < CCS_QUANTITY; index++)
  6048. {
  6049. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6050. {
  6051. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6052. }
  6053. }
  6054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6055. }
  6056. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6057. {
  6058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6059. {
  6060. tempIndex = ((gun_index==2) ? 1: 0);
  6061. }
  6062. else
  6063. {
  6064. tempIndex = gun_index;
  6065. }
  6066. for (int index = 0; index < GB_QUANTITY; index++)
  6067. {
  6068. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6069. {
  6070. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6071. }
  6072. }
  6073. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6074. }
  6075. else if(gunType[gun_index] == GUN_TYPE_DO)
  6076. {
  6077. tempIndex = gun_index;
  6078. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6083. }
  6084. }
  6085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6086. }
  6087. else
  6088. {
  6089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6090. {
  6091. tempIndex = 2;
  6092. }
  6093. else
  6094. {
  6095. tempIndex = gun_index;
  6096. }
  6097. for (int index = 0; index < AC_QUANTITY; index++)
  6098. {
  6099. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6100. {
  6101. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6102. }
  6103. }
  6104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6105. }
  6106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6111. }
  6112. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6113. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6114. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6115. (dataType == ReadingContext_Trigger))
  6116. {
  6117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6119. {
  6120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6121. {
  6122. tempIndex = ((gun_index==2) ? 1: 0);
  6123. }
  6124. else
  6125. {
  6126. tempIndex = gun_index;
  6127. }
  6128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6131. {
  6132. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6133. }
  6134. } // END OF FOR CHAdeMO_QUANTITY
  6135. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6136. }
  6137. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6138. {
  6139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6140. {
  6141. tempIndex = ((gun_index==2) ? 1: 0);
  6142. }
  6143. else
  6144. {
  6145. tempIndex = gun_index;
  6146. }
  6147. for (int index = 0; index < CCS_QUANTITY; index++)
  6148. {
  6149. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6150. {
  6151. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6152. }
  6153. } // END OF CCS_QUANTITY
  6154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6155. }
  6156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6157. {
  6158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6159. {
  6160. tempIndex = ((gun_index==2) ? 1: 0);
  6161. }
  6162. else
  6163. {
  6164. tempIndex = gun_index;
  6165. }
  6166. for (int index = 0; index < GB_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6171. }
  6172. } // END OF GB_QUANTITY
  6173. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6174. }
  6175. else if(gunType[gun_index] == GUN_TYPE_DO)
  6176. {
  6177. tempIndex = gun_index;
  6178. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6179. {
  6180. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6181. {
  6182. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6183. }
  6184. }
  6185. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6186. }
  6187. else
  6188. {
  6189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6190. {
  6191. tempIndex = 2;
  6192. }
  6193. else
  6194. {
  6195. tempIndex = gun_index;
  6196. }
  6197. for (int index = 0; index < AC_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6200. {
  6201. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6202. }
  6203. }
  6204. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6205. }
  6206. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6207. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6208. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6209. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6210. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6211. }
  6212. //********************************(4)Power.Active.Import************************************************/
  6213. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6214. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6215. (dataType == ReadingContext_Trigger))
  6216. {
  6217. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6218. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6219. {
  6220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6221. {
  6222. tempIndex = ((gun_index==2) ? 1: 0);
  6223. }
  6224. else
  6225. {
  6226. tempIndex = gun_index;
  6227. }
  6228. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6229. {
  6230. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6231. {
  6232. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6233. }
  6234. } // END OF FOR
  6235. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6236. }
  6237. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6238. {
  6239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6240. {
  6241. tempIndex = ((gun_index==2) ? 1: 0);
  6242. }
  6243. else
  6244. {
  6245. tempIndex = gun_index;
  6246. }
  6247. for (int index = 0; index < CCS_QUANTITY; index++)
  6248. {
  6249. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6250. {
  6251. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6252. }
  6253. }
  6254. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6255. }
  6256. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6257. {
  6258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6259. {
  6260. tempIndex = ((gun_index==2) ? 1: 0);
  6261. }
  6262. else
  6263. {
  6264. tempIndex = gun_index;
  6265. }
  6266. for (int index = 0; index < GB_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6269. {
  6270. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6271. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6272. }
  6273. }
  6274. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6275. }
  6276. else if(gunType[gun_index] == GUN_TYPE_DO)
  6277. {
  6278. tempIndex = gun_index;
  6279. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6280. {
  6281. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6282. {
  6283. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6284. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6285. }
  6286. }
  6287. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6288. }
  6289. else
  6290. {
  6291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6292. {
  6293. tempIndex = 2;
  6294. }
  6295. else
  6296. {
  6297. tempIndex = gun_index;
  6298. }
  6299. for (int index = 0; index < AC_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6302. {
  6303. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6304. }
  6305. }
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6307. }
  6308. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6309. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6310. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6311. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6312. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6313. }
  6314. //***********************************************(5)VOLTAGE L1******************************************************/
  6315. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6316. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6317. (dataType == ReadingContext_Trigger))
  6318. {
  6319. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6320. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6321. {
  6322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6323. {
  6324. tempIndex = ((gun_index==2) ? 1: 0);
  6325. }
  6326. else
  6327. {
  6328. tempIndex = gun_index;
  6329. }
  6330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6331. {
  6332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6333. {
  6334. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6335. }
  6336. }
  6337. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6338. }
  6339. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6340. {
  6341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6342. {
  6343. tempIndex = ((gun_index==2) ? 1: 0);
  6344. }
  6345. else
  6346. {
  6347. tempIndex = gun_index;
  6348. }
  6349. for (int index = 0; index < CCS_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6354. }
  6355. }
  6356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6357. }
  6358. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6359. {
  6360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6361. {
  6362. tempIndex = ((gun_index==2) ? 1: 0);
  6363. }
  6364. else
  6365. {
  6366. tempIndex = gun_index;
  6367. }
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6373. }
  6374. }
  6375. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6376. }
  6377. else if(gunType[gun_index] == GUN_TYPE_DO)
  6378. {
  6379. tempIndex = gun_index;
  6380. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6381. {
  6382. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6383. {
  6384. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6385. }
  6386. }
  6387. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6388. }
  6389. else
  6390. {
  6391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6392. {
  6393. tempIndex = 2;
  6394. }
  6395. else
  6396. {
  6397. tempIndex = gun_index;
  6398. }
  6399. for (int index = 0; index < AC_QUANTITY; index++)
  6400. {
  6401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6402. {
  6403. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6404. }
  6405. }
  6406. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6407. }
  6408. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6409. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6410. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6412. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6413. }
  6414. //***********************************************(6)SOC******************************************************/
  6415. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6416. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6417. (dataType == ReadingContext_Trigger))
  6418. {
  6419. 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))
  6420. {
  6421. //idx_sample=5;
  6422. //sampledValue = NULL;
  6423. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6424. {
  6425. tempIndex = ((gun_index==2) ? 1: 0);
  6426. }
  6427. else
  6428. {
  6429. tempIndex = gun_index;
  6430. }
  6431. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6432. {
  6433. //tempIndex = ((gun_index==2) ? 1: 0);
  6434. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6435. {
  6436. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6437. {
  6438. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6439. }
  6440. }
  6441. }
  6442. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6443. {
  6444. //tempIndex = ((gun_index==2) ? 1: 0);
  6445. for (int index = 0; index < CCS_QUANTITY; index++)
  6446. {
  6447. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6448. {
  6449. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6450. }
  6451. }
  6452. }
  6453. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6454. {
  6455. //tempIndex = ((gun_index==2) ? 1: 0);
  6456. for (int index = 0; index < GB_QUANTITY; index++)
  6457. {
  6458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6459. {
  6460. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6461. }
  6462. }
  6463. }
  6464. else if(gunType[gun_index] == GUN_TYPE_DO)
  6465. {
  6466. //tempIndex = ((gun_index==2) ? 1: 0);
  6467. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6468. {
  6469. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6470. {
  6471. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6472. }
  6473. }
  6474. }
  6475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6476. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6478. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6481. }
  6482. }
  6483. //********************************(7)Current.Import L2************************************************/
  6484. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6485. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6486. (dataType == ReadingContext_Trigger))
  6487. {
  6488. // Only for AC 3 phase
  6489. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6490. {
  6491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6492. {
  6493. tempIndex = 2;
  6494. }
  6495. else
  6496. {
  6497. tempIndex = gun_index;
  6498. }
  6499. for (int index = 0; index < AC_QUANTITY; index++)
  6500. {
  6501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6502. {
  6503. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6504. }
  6505. }
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6507. }
  6508. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6513. }
  6514. //********************************(8)Current.Import L3************************************************/
  6515. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6516. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6517. (dataType == ReadingContext_Trigger))
  6518. {
  6519. // Only for AC 3 phase
  6520. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6521. {
  6522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6523. {
  6524. tempIndex = 2;
  6525. }
  6526. else
  6527. {
  6528. tempIndex = gun_index;
  6529. }
  6530. for (int index = 0; index < AC_QUANTITY; index++)
  6531. {
  6532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6533. {
  6534. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6535. }
  6536. }
  6537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6538. }
  6539. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6540. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6541. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6542. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6543. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6544. }
  6545. //***********************************************(9)VOLTAGE L2******************************************************/
  6546. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6547. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6548. (dataType == ReadingContext_Trigger))
  6549. {
  6550. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6551. {
  6552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6553. {
  6554. tempIndex = 2;
  6555. }
  6556. else
  6557. {
  6558. tempIndex = gun_index;
  6559. }
  6560. for (int index = 0; index < AC_QUANTITY; index++)
  6561. {
  6562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6563. {
  6564. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6565. }
  6566. }
  6567. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6568. }
  6569. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6570. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6571. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6572. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6573. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6574. }
  6575. //***********************************************(10)VOLTAGE L3******************************************************/
  6576. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6577. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6578. (dataType == ReadingContext_Trigger))
  6579. {
  6580. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6581. {
  6582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6583. {
  6584. tempIndex = 2;
  6585. }
  6586. else
  6587. {
  6588. tempIndex = gun_index;
  6589. }
  6590. for (int index = 0; index < AC_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6593. {
  6594. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6595. }
  6596. }
  6597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6598. }
  6599. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6601. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6602. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6603. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6604. }
  6605. //***********************************************(11)Current.Offered******************************************************/
  6606. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6607. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6608. (dataType == ReadingContext_Trigger))
  6609. {
  6610. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6611. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6612. {
  6613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6614. {
  6615. tempIndex = ((gun_index==2) ? 1: 0);
  6616. }
  6617. else
  6618. {
  6619. tempIndex = gun_index;
  6620. }
  6621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6622. {
  6623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6624. {
  6625. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6626. }
  6627. } // END OF FOR CHAdeMO_QUANTITY
  6628. }
  6629. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6630. {
  6631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6632. {
  6633. tempIndex = ((gun_index==2) ? 1: 0);
  6634. }
  6635. else
  6636. {
  6637. tempIndex = gun_index;
  6638. }
  6639. for (int index = 0; index < CCS_QUANTITY; index++)
  6640. {
  6641. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6642. {
  6643. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6644. }
  6645. } // END OF CCS_QUANTITY
  6646. }
  6647. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6648. {
  6649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6650. {
  6651. tempIndex = ((gun_index==2) ? 1: 0);
  6652. }
  6653. else
  6654. {
  6655. tempIndex = gun_index;
  6656. }
  6657. for (int index = 0; index < GB_QUANTITY; index++)
  6658. {
  6659. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6660. {
  6661. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6662. }
  6663. } // END OF GB_QUANTITY
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_DO)
  6666. {
  6667. tempIndex = gun_index;
  6668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6671. {
  6672. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6673. }
  6674. }
  6675. }
  6676. else
  6677. {
  6678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6679. {
  6680. tempIndex = 2;
  6681. }
  6682. else
  6683. {
  6684. tempIndex = gun_index;
  6685. }
  6686. for (int index = 0; index < AC_QUANTITY; index++)
  6687. {
  6688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6689. {
  6690. uint16_t currentOffer;
  6691. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6692. {
  6693. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6694. }
  6695. else
  6696. {
  6697. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6698. }
  6699. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6700. }
  6701. }
  6702. }
  6703. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6704. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6705. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6706. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6707. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6708. }
  6709. //***********************************************(12)Power.Offered******************************************************/
  6710. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6711. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6712. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6713. {
  6714. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6715. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6716. {
  6717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6718. {
  6719. tempIndex = ((gun_index==2) ? 1: 0);
  6720. }
  6721. else
  6722. {
  6723. tempIndex = gun_index;
  6724. }
  6725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6726. {
  6727. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6728. {
  6729. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6730. }
  6731. } // END OF FOR CHAdeMO_QUANTITY
  6732. }
  6733. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6734. {
  6735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6736. {
  6737. tempIndex = ((gun_index==2) ? 1: 0);
  6738. }
  6739. else
  6740. {
  6741. tempIndex = gun_index;
  6742. }
  6743. for (int index = 0; index < CCS_QUANTITY; index++)
  6744. {
  6745. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6746. {
  6747. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6748. }
  6749. } // END OF CCS_QUANTITY
  6750. }
  6751. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6752. {
  6753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6754. {
  6755. tempIndex = ((gun_index==2) ? 1: 0);
  6756. }
  6757. else
  6758. {
  6759. tempIndex = gun_index;
  6760. }
  6761. for (int index = 0; index < GB_QUANTITY; index++)
  6762. {
  6763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6764. {
  6765. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6766. }
  6767. } // END OF GB_QUANTITY
  6768. }
  6769. else if(gunType[gun_index] == GUN_TYPE_DO)
  6770. {
  6771. tempIndex = gun_index;
  6772. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6773. {
  6774. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6775. {
  6776. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6777. }
  6778. }
  6779. }
  6780. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6781. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6782. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6783. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6784. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6785. }
  6786. // Message create ====================================================================================================
  6787. if(TRUE)
  6788. {
  6789. json_object *MeterValueReq = json_object_new_object();
  6790. json_object *MeterValues = json_object_new_array();
  6791. json_object *sampledValues = json_object_new_array();
  6792. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6793. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6794. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6795. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6796. {
  6797. json_object *MeterValue = json_object_new_object();
  6798. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6799. {
  6800. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6801. {
  6802. json_object *sampledValue = json_object_new_object();
  6803. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6804. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6805. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6806. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6807. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6808. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6809. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6810. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6811. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6812. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6813. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6814. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6815. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6816. json_object_array_add(sampledValues, sampledValue);
  6817. }
  6818. }
  6819. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6820. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6821. json_object_array_add(MeterValues, MeterValue);
  6822. }
  6823. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6824. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6825. ,gun_index + 1
  6826. ,MESSAGE_TYPE_CALL
  6827. ,guid
  6828. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6829. json_object_put(MeterValueReq);
  6830. }
  6831. // Put request guid to hash map
  6832. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6833. 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*/)
  6834. {
  6835. result = PASS;
  6836. //DEBUG_INFO("MeterValues mapitem pass\n");
  6837. }
  6838. if((dataType != ReadingContext_Trigger) &&
  6839. (dataType != ReadingContext_Sample_Clock) &&
  6840. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6841. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6842. else
  6843. {
  6844. if(FirstHeartBeat)
  6845. LWS_Send(queuedata +2);
  6846. }
  6847. return result;
  6848. }
  6849. int sendLogStatusNotificationRequest(char *status)
  6850. {
  6851. mtrace();
  6852. int result = PASS;
  6853. char message[4096]={0};
  6854. char guid[37]={0};
  6855. char tempdata[128]={0};
  6856. json_object *LogStatusNotification = json_object_new_object();
  6857. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6858. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6859. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6860. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6861. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6862. random_uuid(guid);
  6863. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6864. json_object_put(LogStatusNotification);
  6865. LWS_Send(message);
  6866. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6867. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6868. {
  6869. result = PASS;
  6870. }
  6871. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6872. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6873. return result;
  6874. }
  6875. int sendSecurityEventNotificationRequest()
  6876. {
  6877. mtrace();
  6878. int result = PASS;
  6879. char message[4096]={0};
  6880. char guid[37]={0};
  6881. char tempdata[128]={0};
  6882. json_object *SecurityEventNotification = json_object_new_object();
  6883. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6884. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6885. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6886. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6887. random_uuid(guid);
  6888. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6889. json_object_put(SecurityEventNotification);
  6890. LWS_Send(message);
  6891. sprintf(tempdata, "SecurityEventNotification,0");
  6892. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6893. {
  6894. result = PASS;
  6895. }
  6896. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6897. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6898. return result;
  6899. }
  6900. int sendSignCertificateRequest()
  6901. {
  6902. mtrace();
  6903. int result = PASS;
  6904. char message[4096]={0};
  6905. char guid[37]={0};
  6906. char tempdata[128]={0};
  6907. json_object *SignCertificate = json_object_new_object();
  6908. DEBUG_INFO("sendSignCertificateRequest...\n");
  6909. // Read csr file content
  6910. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6911. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6912. char *line = NULL;
  6913. size_t len = 0;
  6914. while(getline(&line, &len, fp) != -1)
  6915. {
  6916. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6917. {
  6918. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6919. }
  6920. }
  6921. fclose(fp);
  6922. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6923. random_uuid(guid);
  6924. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6925. json_object_put(SignCertificate);
  6926. LWS_Send(message);
  6927. sprintf(tempdata, "SignCertificate,0");
  6928. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6929. {
  6930. result = PASS;
  6931. }
  6932. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6933. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6934. return result;
  6935. }
  6936. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6937. {
  6938. mtrace();
  6939. int result = PASS;
  6940. char message[110]={0};
  6941. char guid[37]={0};
  6942. char tempdata[65]={0};
  6943. json_object *FirmwareStatusNotification = json_object_new_object();
  6944. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6945. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6946. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6947. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6948. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6949. random_uuid(guid);
  6950. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6951. json_object_put(FirmwareStatusNotification);
  6952. LWS_Send(message);
  6953. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6954. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6955. {
  6956. result = PASS;
  6957. }
  6958. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6959. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6960. return result;
  6961. }
  6962. //==========================================
  6963. // send confirm routine
  6964. //==========================================
  6965. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6966. {
  6967. mtrace();
  6968. int result = FAIL;
  6969. char message[100]={0};
  6970. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6972. LWS_Send(message);
  6973. result = TRUE;
  6974. return result;
  6975. }
  6976. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6977. {
  6978. mtrace();
  6979. int result = FAIL;
  6980. char message[100]={0};
  6981. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6982. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6983. LWS_Send(message);
  6984. result = TRUE;
  6985. return result;
  6986. }
  6987. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6988. {
  6989. mtrace();
  6990. int result = FAIL;
  6991. char message[100]={0};
  6992. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6993. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6994. LWS_Send(message);
  6995. result = TRUE;
  6996. return result;
  6997. }
  6998. int sendClearCacheConfirmation(char *uuid,char *payload)
  6999. {
  7000. mtrace();
  7001. int result = FAIL;
  7002. char message[500]={0};
  7003. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7004. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7005. LWS_Send(message);
  7006. return result;
  7007. }
  7008. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7009. {
  7010. mtrace();
  7011. int result = FAIL;
  7012. char message[500]={0};
  7013. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7014. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7015. LWS_Send(message);
  7016. return result;
  7017. }
  7018. int sendDataTransferConfirmation(char *uuid,char *payload)
  7019. {
  7020. mtrace();
  7021. char statusStr[20]={0};
  7022. char dataStr[10]={0};
  7023. char sstr[20]={0};
  7024. int c = 0;
  7025. char *loc;
  7026. int result = FAIL;
  7027. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7028. /**********************status**************************/
  7029. loc = strstr(payload, "status");
  7030. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7031. c = 0;
  7032. while (loc[3+strlen("status")+c] != '\"')
  7033. {
  7034. sstr[c] = loc[3+strlen("status")+c];
  7035. c++;
  7036. }
  7037. sstr[c] = '\0';
  7038. strcpy(statusStr, sstr);
  7039. /**********************data**************************/
  7040. loc = strstr(payload, "data");
  7041. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7042. c = 0;
  7043. while (loc[3+strlen("data")+c] != '\"')
  7044. {
  7045. sstr[c] = loc[3+strlen("data")+c];
  7046. c++;
  7047. }
  7048. sstr[c] = '\0';
  7049. strcpy(dataStr, sstr);
  7050. return result;
  7051. }
  7052. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7053. {
  7054. mtrace();
  7055. int result = FAIL;
  7056. char message[1000]={0};
  7057. int CompositeScheduleIndex = 0;
  7058. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7059. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7060. if(nPeriod == 0)
  7061. {
  7062. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7063. {
  7064. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7065. ,MESSAGE_TYPE_CALLRESULT
  7066. ,uuid
  7067. ,payload
  7068. ,connectorIdInt);
  7069. }
  7070. else
  7071. {
  7072. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7073. ,MESSAGE_TYPE_CALLRESULT
  7074. ,uuid
  7075. ,payload
  7076. ,connectorIdInt
  7077. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7078. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7079. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7080. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7081. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7082. }
  7083. }
  7084. else
  7085. {
  7086. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7087. ,MESSAGE_TYPE_CALLRESULT
  7088. ,uuid
  7089. ,payload
  7090. ,connectorIdInt
  7091. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7092. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7093. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7094. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7095. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7096. {
  7097. if (idx_sample == 0)
  7098. {
  7099. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7100. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7101. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7102. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7103. }
  7104. else
  7105. {
  7106. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7107. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7108. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7109. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7110. }
  7111. }
  7112. sprintf(message + strlen(message), "]}}]");
  7113. }
  7114. LWS_Send(message);
  7115. result = TRUE;
  7116. return result;
  7117. }
  7118. int sendGetConfigurationConfirmation(char *uuid)
  7119. {
  7120. mtrace();
  7121. int result = FAIL;
  7122. int MaxKeySupported = 0;
  7123. int sentConfigurationNumber= 0;
  7124. int sentunConfigurationNumber= 0;
  7125. char message[1024*10]={0};
  7126. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7127. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7128. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7129. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7130. ,MESSAGE_TYPE_CALLRESULT
  7131. ,uuid );
  7132. //configuration key
  7133. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7134. {
  7135. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7136. {
  7137. if (sentConfigurationNumber == 0)
  7138. {
  7139. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7140. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7141. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7142. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7143. }
  7144. else
  7145. {
  7146. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7147. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7148. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7149. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7150. }
  7151. sentConfigurationNumber = sentConfigurationNumber + 1;
  7152. }
  7153. }
  7154. sprintf(message + strlen(message), "]");
  7155. if(UnknownKeynum != 0)
  7156. {
  7157. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7158. //unkown key
  7159. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7160. {
  7161. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7162. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7163. if(sentunConfigurationNumber == 0)
  7164. {
  7165. sprintf(message + strlen(message), "\"%s\""
  7166. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7167. }
  7168. else
  7169. {
  7170. sprintf(message + strlen(message), ",\"%s\""
  7171. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7172. }
  7173. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7174. }
  7175. sprintf(message + strlen(message), "]");
  7176. }
  7177. sprintf(message + strlen(message), "}]");
  7178. LWS_Send(message);
  7179. return result;
  7180. }
  7181. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7182. {
  7183. mtrace();
  7184. int result = FAIL;
  7185. char message[400]={0};
  7186. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7187. if(strcmp(payload,"")==0)
  7188. {
  7189. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7190. }
  7191. else
  7192. {
  7193. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7194. }
  7195. LWS_Send(message);
  7196. result = TRUE;
  7197. return result;
  7198. }
  7199. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7200. {
  7201. mtrace();
  7202. int result = FAIL;
  7203. char message[80]={0};
  7204. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7205. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7206. LWS_Send(message);
  7207. result = TRUE;
  7208. return result;
  7209. }
  7210. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7211. {
  7212. mtrace();
  7213. int result = FAIL;
  7214. char message[80]={0};
  7215. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7216. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7217. LWS_Send(message);
  7218. result = TRUE;
  7219. return result;
  7220. }
  7221. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7222. {
  7223. mtrace();
  7224. int result = FAIL;
  7225. char message[80]={0};
  7226. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7227. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7228. LWS_Send(message);
  7229. result = TRUE;
  7230. return result;
  7231. }
  7232. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7233. {
  7234. mtrace();
  7235. int result = FAIL;
  7236. char message[80]={0};
  7237. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7238. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7239. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7240. LWS_Send(message);
  7241. result = TRUE;
  7242. return result;
  7243. }
  7244. int sendResetConfirmation(char *uuid,char *payload)
  7245. {
  7246. mtrace();
  7247. int result = FAIL;
  7248. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7249. char message[80]={0};
  7250. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7251. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7252. LWS_Send(message);
  7253. result = TRUE;
  7254. return result;
  7255. }
  7256. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7257. {
  7258. mtrace();
  7259. int result = FAIL;
  7260. char message[500]={0};
  7261. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7262. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7263. LWS_Send(message);
  7264. result = TRUE;
  7265. return result;
  7266. }
  7267. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7268. {
  7269. mtrace();
  7270. int result = FAIL;
  7271. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7272. char message[80]={0};
  7273. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7274. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7275. LWS_Send(message);
  7276. result = TRUE;
  7277. return result;
  7278. }
  7279. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7280. {
  7281. mtrace();
  7282. int result = FAIL;
  7283. char message[80]={0};
  7284. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7285. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7286. LWS_Send(message);
  7287. result = TRUE;
  7288. return result;
  7289. }
  7290. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7291. {
  7292. mtrace();
  7293. int result = FAIL;
  7294. char message[80]={0};
  7295. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7296. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7297. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7298. LWS_Send(message);
  7299. result = TRUE;
  7300. return result;
  7301. }
  7302. int sendUpdateFirmwareConfirmation(char *uuid)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. char message[60]={0};
  7307. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7308. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7309. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7310. LWS_Send(message);
  7311. result = TRUE;
  7312. return result;
  7313. }
  7314. int sendCertificateSignedConfirmation(char *uuid)
  7315. {
  7316. mtrace();
  7317. int result = PASS;
  7318. char message[4096]={0};
  7319. json_object *CertificateSigned = json_object_new_object();
  7320. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7321. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7322. sprintf(message,"[%d,\"%s\",%s]"
  7323. ,MESSAGE_TYPE_CALLRESULT
  7324. ,uuid
  7325. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7326. json_object_put(CertificateSigned);
  7327. LWS_Send(message);
  7328. return result;
  7329. }
  7330. int sendDeleteCertificateConfirmation(char *uuid)
  7331. {
  7332. mtrace();
  7333. int result = PASS;
  7334. char message[4096]={0};
  7335. json_object *DeleteCertificate = json_object_new_object();
  7336. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7337. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7338. sprintf(message,"[%d,\"%s\",%s]"
  7339. ,MESSAGE_TYPE_CALLRESULT
  7340. ,uuid
  7341. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7342. json_object_put(DeleteCertificate);
  7343. LWS_Send(message);
  7344. return result;
  7345. }
  7346. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7347. {
  7348. mtrace();
  7349. int result = PASS;
  7350. char message[4096]={0};
  7351. json_object *ExtendedTriggerMessage = json_object_new_object();
  7352. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7353. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7354. sprintf(message,"[%d,\"%s\",%s]"
  7355. ,MESSAGE_TYPE_CALLRESULT
  7356. ,uuid
  7357. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7358. json_object_put(ExtendedTriggerMessage);
  7359. LWS_Send(message);
  7360. return result;
  7361. }
  7362. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7363. {
  7364. mtrace();
  7365. int result = PASS;
  7366. char message[4096]={0};
  7367. json_object *GetInstalledCertificateIds = json_object_new_object();
  7368. json_object *certificateHashDataDatas = json_object_new_array();
  7369. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7370. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7371. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7372. {
  7373. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7374. {
  7375. json_object *certificateHashData = json_object_new_object();
  7376. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7377. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7378. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7379. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7380. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7381. }
  7382. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7383. }
  7384. else
  7385. {
  7386. json_object_put(certificateHashDataDatas);
  7387. }
  7388. sprintf(message,"[%d,\"%s\",%s]"
  7389. ,MESSAGE_TYPE_CALLRESULT
  7390. ,uuid
  7391. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7392. json_object_put(GetInstalledCertificateIds);
  7393. LWS_Send(message);
  7394. return result;
  7395. }
  7396. int sendGetLogConfirmation(char *uuid)
  7397. {
  7398. mtrace();
  7399. int result = PASS;
  7400. char message[4096]={0};
  7401. json_object *GetLog = json_object_new_object();
  7402. DEBUG_INFO("sendGetLogConfirmation...\n");
  7403. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7404. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7405. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7406. sprintf(message,"[%d,\"%s\",%s]"
  7407. ,MESSAGE_TYPE_CALLRESULT
  7408. ,uuid
  7409. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7410. json_object_put(GetLog);
  7411. LWS_Send(message);
  7412. return result;
  7413. }
  7414. int sendInstallCertificateConfirmation(char *uuid)
  7415. {
  7416. mtrace();
  7417. int result = PASS;
  7418. char message[4096]={0};
  7419. json_object *InstallCertificate = json_object_new_object();
  7420. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7421. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7422. sprintf(message,"[%d,\"%s\",%s]"
  7423. ,MESSAGE_TYPE_CALLRESULT
  7424. ,uuid
  7425. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7426. json_object_put(InstallCertificate);
  7427. LWS_Send(message);
  7428. return result;
  7429. }
  7430. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7431. {
  7432. mtrace();
  7433. int result = PASS;
  7434. char message[4096]={0};
  7435. json_object *SignedUpdateFirmware = json_object_new_object();
  7436. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7437. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7438. sprintf(message,"[%d,\"%s\",%s]"
  7439. ,MESSAGE_TYPE_CALLRESULT
  7440. ,uuid
  7441. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7442. json_object_put(SignedUpdateFirmware);
  7443. LWS_Send(message);
  7444. return result;
  7445. }
  7446. int sendUnknownConfirmation(char *uuid)
  7447. {
  7448. mtrace();
  7449. int result = PASS;
  7450. char message[256]={0};
  7451. DEBUG_INFO("sendUnknownConfirmation...\n");
  7452. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7453. LWS_Send(message);
  7454. return result;
  7455. }
  7456. //==========================================
  7457. // Handle server request routine Start
  7458. //==========================================
  7459. int handleCancelReservationRequest(char *uuid, char *payload)
  7460. {
  7461. mtrace();
  7462. int result = FAIL;
  7463. int gunNO = 0;
  7464. int reservationIdInt = -1;
  7465. char comfirmstr[20];
  7466. DEBUG_INFO("handleCancelReservationRequest...\n");
  7467. json_object *CancelReservation;
  7468. CancelReservation = json_tokener_parse(payload);
  7469. if(!is_error(CancelReservation))
  7470. {
  7471. // Required data
  7472. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7473. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7474. }
  7475. json_object_put(CancelReservation);
  7476. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7477. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7478. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7479. if(reservationIdInt != -1)
  7480. {
  7481. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7482. //check Transaction active
  7483. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7485. {
  7486. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7487. {
  7488. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7489. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7490. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7491. {
  7492. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7493. }
  7494. else
  7495. {
  7496. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7497. }
  7498. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7499. goto end;
  7500. }
  7501. }
  7502. for (int index = 0; index < CCS_QUANTITY; index++)
  7503. {
  7504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7505. {
  7506. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7507. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7508. if(gunType[2] == GUN_TYPE_CCS)
  7509. {
  7510. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7511. }
  7512. else
  7513. {
  7514. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7515. }
  7516. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7517. goto end;
  7518. }
  7519. }
  7520. for (int index = 0; index < GB_QUANTITY; index++)
  7521. {
  7522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7523. {
  7524. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7525. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7526. if(gunType[2] == GUN_TYPE_GBT)
  7527. {
  7528. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7529. }
  7530. else
  7531. {
  7532. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7533. }
  7534. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7535. goto end;
  7536. }
  7537. }
  7538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7539. {
  7540. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7541. {
  7542. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7543. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7544. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7545. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7546. goto end;
  7547. }
  7548. }
  7549. for (int index = 0; index < AC_QUANTITY; index++)
  7550. {
  7551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7552. {
  7553. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7554. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7556. {
  7557. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7558. }
  7559. else
  7560. {
  7561. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7562. }
  7563. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7564. goto end;
  7565. }
  7566. }
  7567. }
  7568. //The reservationId does NOT match the reservationId
  7569. sendCancelReservationConfirmation(uuid, comfirmstr);
  7570. end:
  7571. // Fill in ocpp packet uuid
  7572. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7573. return result;
  7574. }
  7575. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7576. {
  7577. mtrace();
  7578. int result = FAIL;
  7579. int gunIndex = -1;
  7580. char typeStr[16]={0};
  7581. char comfirmstr[20];
  7582. int specificId = FALSE;
  7583. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7584. json_object *ChangeAvailability;
  7585. ChangeAvailability = json_tokener_parse(payload);
  7586. if(!is_error(ChangeAvailability))
  7587. {
  7588. // Required data
  7589. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7590. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7591. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7592. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7593. }
  7594. json_object_put(ChangeAvailability);
  7595. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7596. {
  7597. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7598. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7599. }
  7600. else if(gunIndex == 0)
  7601. {
  7602. for(int i=0; i < gunTotalNumber; i++)
  7603. {
  7604. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7605. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7606. }
  7607. }
  7608. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7610. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7611. {
  7612. specificId = TRUE;
  7613. }
  7614. if(specificId == FALSE)
  7615. goto end;
  7616. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7617. {
  7618. //----------------------gunIndex is 0 ------------------------------------------------//
  7619. if(gunIndex == 0)
  7620. {
  7621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7622. {
  7623. for(int i=0; i < gunTotalNumber; i++)
  7624. {
  7625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7626. {
  7627. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7628. {
  7629. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7630. {
  7631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7632. goto end;
  7633. }
  7634. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7635. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7636. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7637. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7638. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7639. {
  7640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7641. goto end;
  7642. }
  7643. }
  7644. }//END FOR CHAdeMO_QUANTITY
  7645. for (int index = 0; index < CCS_QUANTITY; index++)
  7646. {
  7647. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7648. {
  7649. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7650. {
  7651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7652. goto end;
  7653. }
  7654. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7655. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7656. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7657. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7658. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7659. {
  7660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7661. goto end;
  7662. }
  7663. }
  7664. }//END FOR CCS_QUANTITY
  7665. for (int index = 0; index < GB_QUANTITY; index++)
  7666. {
  7667. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7668. {
  7669. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7670. {
  7671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7672. goto end;
  7673. }
  7674. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7676. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7677. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7678. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7679. {
  7680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7681. goto end;
  7682. }
  7683. }
  7684. }// END FOR GB_QUANTITY
  7685. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7686. {
  7687. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7688. {
  7689. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7690. {
  7691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7692. goto end;
  7693. }
  7694. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7695. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7696. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7697. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7698. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7699. {
  7700. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7701. goto end;
  7702. }
  7703. }
  7704. }// END FOR GENERAL_GUN_QUANTITY
  7705. for (int index = 0; index < AC_QUANTITY; index++)
  7706. {
  7707. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7708. {
  7709. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7710. {
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7712. goto end;
  7713. }
  7714. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7715. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7716. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7717. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7718. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7719. {
  7720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7721. goto end;
  7722. }
  7723. }
  7724. }//END FOR AC_QUANTITY
  7725. }// END FOR gunTotalNumber
  7726. }
  7727. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7728. {
  7729. for(int i=0; i < gunTotalNumber; i++)
  7730. {
  7731. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7732. {
  7733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7734. goto end;
  7735. }
  7736. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7737. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7738. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7739. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7740. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7741. {
  7742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7743. goto end;
  7744. }
  7745. }
  7746. }
  7747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7748. goto end;
  7749. }
  7750. //----------------------gunIndex is not 0 ------------------------------------------------//
  7751. //check Transaction active
  7752. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7753. {
  7754. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7755. {
  7756. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7757. {
  7758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7759. goto end;
  7760. }
  7761. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7762. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7763. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7764. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7765. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7766. {
  7767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7768. goto end;
  7769. }
  7770. else
  7771. {
  7772. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7773. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7774. goto end;
  7775. }
  7776. }
  7777. }//END FOR CHAdeMO_QUANTITY
  7778. for (int index = 0; index < CCS_QUANTITY; index++)
  7779. {
  7780. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7781. {
  7782. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7783. {
  7784. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7785. goto end;
  7786. }
  7787. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7788. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7789. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7790. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7791. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7792. {
  7793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7794. goto end;
  7795. }
  7796. else
  7797. {
  7798. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7799. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7800. goto end;
  7801. }
  7802. }
  7803. }//END FOR CCS_QUANTITY
  7804. for (int index = 0; index < GB_QUANTITY; index++)
  7805. {
  7806. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7807. {
  7808. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7809. {
  7810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7811. goto end;
  7812. }
  7813. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7814. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7815. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7816. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7817. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7818. {
  7819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7820. goto end;
  7821. }
  7822. else
  7823. {
  7824. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7826. goto end;
  7827. }
  7828. }
  7829. }// END FOR GB_QUANTITY
  7830. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7831. {
  7832. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7833. {
  7834. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7835. {
  7836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7837. goto end;
  7838. }
  7839. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7840. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7841. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7842. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7843. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7844. {
  7845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7846. goto end;
  7847. }
  7848. else
  7849. {
  7850. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7852. goto end;
  7853. }
  7854. }
  7855. }// END FOR GENERAL_GUN_QUANTITY
  7856. for (int index = 0; index < AC_QUANTITY; index++)
  7857. {
  7858. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7859. {
  7860. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7861. {
  7862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7863. goto end;
  7864. }
  7865. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7866. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7867. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7868. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7869. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7870. {
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7872. goto end;
  7873. }
  7874. else
  7875. {
  7876. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7878. goto end;
  7879. }
  7880. }
  7881. }//END FOR AC_QUANTITY
  7882. }//END FOR AvailabilityTypeStr[Inoperative]
  7883. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7884. {
  7885. //----------------------gunIndex is 0 ------------------------------------------------//
  7886. if(gunIndex == 0)
  7887. {
  7888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7889. {
  7890. for(int i=0; i < gunTotalNumber; i++)
  7891. {
  7892. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7893. {
  7894. 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
  7895. {
  7896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7897. goto end;
  7898. }
  7899. }//END FOR CHAdeMO_QUANTITY
  7900. for (int index = 0; index < CCS_QUANTITY; index++)
  7901. {
  7902. 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
  7903. {
  7904. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7905. goto end;
  7906. }
  7907. }//END FOR CCS_QUANTITY
  7908. for (int index = 0; index < GB_QUANTITY; index++)
  7909. {
  7910. 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
  7911. {
  7912. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7913. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7914. goto end;
  7915. }
  7916. }// END FOR GB_QUANTITY
  7917. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7918. {
  7919. 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
  7920. {
  7921. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7923. goto end;
  7924. }
  7925. }// END FOR GENERAL_GUN_QUANTITY
  7926. for (int index = 0; index < AC_QUANTITY; index++)
  7927. {
  7928. 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
  7929. {
  7930. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7931. goto end;
  7932. }
  7933. }//END FOR CHAdeMO_QUANTITY
  7934. }// END FOR gunTotalNumber
  7935. }
  7936. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7937. {
  7938. for(int i=0; i < gunTotalNumber; i++)
  7939. {
  7940. for (int index = 0; index < AC_QUANTITY; index++)
  7941. {
  7942. 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
  7943. {
  7944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7945. goto end;
  7946. }
  7947. }//END FOR CHAdeMO_QUANTITY
  7948. } // END FOR gunTotalNumber
  7949. }
  7950. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7951. goto end;
  7952. }
  7953. //----------------------gunIndex is not 0 ------------------------------------------------//
  7954. //check Transaction active
  7955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7956. {
  7957. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7958. {
  7959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7960. goto end;
  7961. }
  7962. }//END FOR CHAdeMO_QUANTITY
  7963. for (int index = 0; index < CCS_QUANTITY; index++)
  7964. {
  7965. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7966. {
  7967. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7968. goto end;
  7969. }
  7970. }//END FOR CCS_QUANTITY
  7971. for (int index = 0; index < GB_QUANTITY; index++)
  7972. {
  7973. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7974. {
  7975. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7976. goto end;
  7977. }
  7978. }// END FOR GB_QUANTITY
  7979. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7980. {
  7981. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7982. {
  7983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7984. goto end;
  7985. }
  7986. }// END FOR GENERAL_GUN_QUANTITY
  7987. for (int index = 0; index < AC_QUANTITY; index++)
  7988. {
  7989. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7990. {
  7991. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7992. goto end;
  7993. }
  7994. }//END FOR AC_QUANTITY
  7995. }//END FOR AvailabilityTypeStr[Operative]
  7996. end:
  7997. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7998. {
  7999. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8000. }
  8001. else
  8002. {
  8003. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8004. }
  8005. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8006. {
  8007. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8008. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8009. }
  8010. else if(gunIndex == 0)
  8011. {
  8012. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8013. {
  8014. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8015. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8016. }
  8017. }
  8018. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8019. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8020. return result;
  8021. }
  8022. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8023. {
  8024. mtrace();
  8025. int valueInvalid = NO;
  8026. int result = FAIL;
  8027. char keystr[40]={0};
  8028. char valuestr[501]={0}; //value should be limited in 500 bytes
  8029. char comfirmstr[20]={0};
  8030. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8031. json_object *ChangeConfiguration;
  8032. ChangeConfiguration = json_tokener_parse(payload);
  8033. if(!is_error(ChangeConfiguration))
  8034. {
  8035. // Required data
  8036. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8037. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8038. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8039. {
  8040. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8041. }
  8042. else
  8043. {
  8044. valueInvalid = YES;
  8045. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8046. }
  8047. }
  8048. json_object_put(ChangeConfiguration);
  8049. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8050. {
  8051. DEBUG_ERROR("Payload is null or not accepted.\n");
  8052. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8053. }
  8054. else
  8055. {
  8056. int status = setKeyValue(keystr, valuestr);
  8057. switch(status)
  8058. {
  8059. case ConfigurationStatus_Accepted:
  8060. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8061. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8062. StoreConfigurationTable();
  8063. break;
  8064. case RebootRequired:
  8065. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8066. StoreConfigurationTable();
  8067. break;
  8068. case NotSupported:
  8069. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8070. break;
  8071. case ConfigurationStatus_Rejected:
  8072. default:
  8073. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8074. break;
  8075. }
  8076. }
  8077. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8078. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8079. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8080. {
  8081. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8082. SetOcppConnStatus(FALSE);
  8083. }
  8084. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8085. {
  8086. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8087. }
  8088. return result;
  8089. }
  8090. int handleClearCacheRequest(char *uuid, char *payload)
  8091. {
  8092. mtrace();
  8093. int result = FAIL;
  8094. char comfirmstr[20];
  8095. char rmFileCmd[100]={0};
  8096. struct stat stats;
  8097. DEBUG_INFO("handleClearCacheRequest...\n");
  8098. stat("/Storage/OCPP_PH", &stats);
  8099. // Check for directory existence
  8100. if (S_ISDIR(stats.st_mode) == 1)
  8101. {}
  8102. else
  8103. {
  8104. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8105. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8106. system(rmFileCmd);
  8107. }
  8108. if(OCPP_cleanLocalCache())
  8109. {
  8110. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8111. }
  8112. else
  8113. {
  8114. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8115. }
  8116. sendClearCacheConfirmation(uuid, comfirmstr);
  8117. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8118. return result;
  8119. }
  8120. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8121. {
  8122. mtrace();
  8123. int result = FAIL;
  8124. int resultRename;
  8125. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8126. char chargingProfilePurposeStr[26]={0};
  8127. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8128. char tempchargingProfilePurposeStr[26]={0};
  8129. char str[100]={0};
  8130. char fname[200]={0};
  8131. char comfirmstr[20]={0};
  8132. char word[1600]={0};
  8133. int clearflag = FALSE;
  8134. int chargingProfileIdIsNULL = FALSE;
  8135. int connectorIsNULL = FALSE;
  8136. int chargingProfilePurposeIsNULL = FALSE;
  8137. int stackLevelIsNULL = FALSE;
  8138. //int GotoEnd = FALSE;
  8139. FILE *fptr1, *fptr2;
  8140. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8141. int n_chargingProfile=0;
  8142. int isEmptyFile = FALSE;
  8143. char sLineWord[1600]={0};
  8144. char chargingProfiles[10][100]={0};
  8145. int ChargeProfileCount = 0;
  8146. int ch;
  8147. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8148. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8149. json_object *ClearChargingProfile;
  8150. ClearChargingProfile = json_tokener_parse(payload);
  8151. if(!is_error(ClearChargingProfile))
  8152. {
  8153. // Optional data
  8154. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8155. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8156. else
  8157. chargingProfileIdIsNULL = TRUE;
  8158. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8159. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8160. else
  8161. connectorIsNULL = TRUE;
  8162. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8163. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8164. else
  8165. chargingProfilePurposeIsNULL = TRUE;
  8166. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8167. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8168. else
  8169. stackLevelIsNULL = TRUE;
  8170. }
  8171. json_object_put(ClearChargingProfile);
  8172. if(connectorIsNULL == FALSE)
  8173. {
  8174. switch(connectorIdInt)
  8175. {
  8176. case 0:
  8177. if(chargingProfilePurposeIsNULL == TRUE)
  8178. {
  8179. int l = 0;
  8180. strcpy(fname, ChargePointMaxProfile_JSON);
  8181. if((access(fname,F_OK))!=-1)
  8182. {
  8183. strcpy(chargingProfiles[l], fname);
  8184. l = l + 1;
  8185. }
  8186. strcpy(fname, TxDefaultProfile_0_JSON);
  8187. if((access(fname,F_OK))!=-1)
  8188. {
  8189. strcpy(chargingProfiles[l], fname);
  8190. l = l + 1;
  8191. }
  8192. ChargeProfileCount = l;
  8193. }
  8194. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8195. {
  8196. strcpy(fname, ChargePointMaxProfile_JSON);
  8197. if((access(fname,F_OK))!=-1)
  8198. {
  8199. strcpy(chargingProfiles[0], fname);
  8200. ChargeProfileCount = 1;
  8201. }
  8202. }
  8203. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8204. {
  8205. strcpy(fname, TxDefaultProfile_0_JSON);
  8206. if((access(fname,F_OK))!=-1)
  8207. {
  8208. strcpy(chargingProfiles[0], fname);
  8209. ChargeProfileCount = 1;
  8210. }
  8211. }
  8212. break;
  8213. default:
  8214. if(chargingProfilePurposeIsNULL == TRUE)
  8215. {
  8216. int m = 0;
  8217. memset(fname, 0, ARRAY_SIZE(fname));
  8218. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8219. if((access(fname,F_OK))!=-1)
  8220. {
  8221. strcpy(chargingProfiles[m], fname);
  8222. m = m + 1;
  8223. }
  8224. memset(fname, 0, ARRAY_SIZE(fname));
  8225. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8226. if((access(fname,F_OK))!=-1)
  8227. {
  8228. strcpy(chargingProfiles[m], fname);
  8229. m = m + 1;
  8230. }
  8231. ChargeProfileCount = m;
  8232. }
  8233. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8234. {
  8235. //strcpy(fname, TxDefaultProfile_1_JSON);
  8236. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8237. if((access(fname,F_OK))!=-1)
  8238. {
  8239. strcpy(chargingProfiles[0], fname);
  8240. ChargeProfileCount = 1;
  8241. }
  8242. }
  8243. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8244. {
  8245. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8246. if((access(fname,F_OK))!=-1)
  8247. {
  8248. strcpy(chargingProfiles[0], fname);
  8249. ChargeProfileCount = 1;
  8250. }
  8251. //strcpy(fname, TxProfile_1_JSON);
  8252. }
  8253. //strcpy(fname, ChargePointMaxProfile_JSON );
  8254. break;
  8255. }
  8256. }
  8257. else // Check all Charging Profiles
  8258. {
  8259. int i = 0;
  8260. char fnametemp[200]={0};
  8261. ChargeProfileCount = 0;
  8262. //Check ChargePointMaxProfile.json exit
  8263. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8264. {
  8265. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8266. i = i + 1;
  8267. }
  8268. //Check TxDefaultProfile_0.json exit
  8269. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8270. {
  8271. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8272. i = i + 1;
  8273. }
  8274. //Check TxDefaultProfile_%d.json
  8275. for(int j=1; j <= gunTotalNumber; j++)
  8276. {
  8277. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8278. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8279. if((access(fnametemp,F_OK))!=-1)
  8280. {
  8281. strcpy(chargingProfiles[i], fnametemp);
  8282. i = i + 1;
  8283. }
  8284. }
  8285. //Check TxProfile_%d.json
  8286. for(int j=1; j <= gunTotalNumber; j++)
  8287. {
  8288. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8289. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8290. if((access(fnametemp,F_OK))!=-1)
  8291. {
  8292. strcpy(chargingProfiles[i], fnametemp);
  8293. i = i + 1;
  8294. }
  8295. }
  8296. ChargeProfileCount = i;
  8297. }// End connectorIsNULL is TRUE
  8298. if(ChargeProfileCount == 0)
  8299. {
  8300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8301. goto end;
  8302. }
  8303. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8304. {
  8305. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8306. goto end;
  8307. }
  8308. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8309. {
  8310. memset(str, 0, ARRAY_SIZE(str));
  8311. // clear temp file
  8312. sprintf(str,"rm -f %s",temp);
  8313. system(str);
  8314. for(int k=0; k < ChargeProfileCount; k++)
  8315. {
  8316. memset(str, 0, ARRAY_SIZE(str));
  8317. //clear file in C
  8318. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8319. system(str);
  8320. }
  8321. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8322. goto end;
  8323. }
  8324. else if(connectorIsNULL == TRUE)
  8325. {
  8326. for(int k=0; k < ChargeProfileCount; k++)
  8327. {
  8328. fptr1 = fopen(chargingProfiles[k], "r");
  8329. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8330. //Check Charging Profile Count
  8331. while(fscanf(fptr1, "%s", word) != EOF)
  8332. {
  8333. //DEBUG_INFO("word=%s\n",word);
  8334. if(strstr(word, "chargingProfileId")!= NULL)
  8335. {
  8336. //DEBUG_INFO("test chargingProfileId \n");
  8337. n_chargingProfile = n_chargingProfile + 1;
  8338. //DEBUG_INFO("chargingProfileId Found\n");
  8339. }
  8340. }
  8341. rewind(fptr1);
  8342. //search Charging Profile Element
  8343. //int i= 0;
  8344. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8345. {
  8346. json_object *tmpProfilee;
  8347. tmpProfilee = json_tokener_parse(sLineWord);
  8348. if(!is_error(tmpProfilee))
  8349. {
  8350. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8351. {
  8352. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8353. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8354. }
  8355. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8356. {
  8357. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8358. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8359. }
  8360. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8361. {
  8362. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8363. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8364. }
  8365. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8366. {
  8367. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8368. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8369. }
  8370. }
  8371. json_object_put(tmpProfilee);
  8372. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8373. {
  8374. //------- not write to fptr2-------//
  8375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8376. //clearflag = TRUE;
  8377. }
  8378. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8379. {
  8380. //------- not write to fptr2-------//
  8381. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8382. }
  8383. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8384. {
  8385. //------- not write to fptr2-------//
  8386. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8387. }
  8388. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8389. {
  8390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8391. }
  8392. else
  8393. {
  8394. fprintf(fptr2, sLineWord);//writing data into file
  8395. }
  8396. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8397. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8398. if(clearflag == TRUE)
  8399. {
  8400. fclose(fptr1);
  8401. fclose(fptr2);
  8402. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8403. system(str);
  8404. // clear temp file
  8405. sprintf(str,"rm -f %s",temp);
  8406. system(str);
  8407. }
  8408. else
  8409. {
  8410. fclose(fptr1);
  8411. fclose(fptr2);
  8412. memset(str, 0, ARRAY_SIZE(str));
  8413. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8414. system(str);
  8415. resultRename = rename(temp, chargingProfiles[k]);
  8416. if(resultRename == 0)
  8417. {
  8418. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8419. }
  8420. else
  8421. {
  8422. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8423. }
  8424. if(comfirmstr[0]== 0)
  8425. {
  8426. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8427. }
  8428. //Check chargingProfile is empty file
  8429. /*------ Read the file ----------------*/
  8430. fptr1=fopen(chargingProfiles[k],"r");
  8431. ch=fgetc(fptr1);
  8432. rewind(fptr1);
  8433. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8434. if(ch!=EOF)
  8435. {
  8436. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8437. {
  8438. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8439. if(sLineWord[0]=='\0')
  8440. {
  8441. isEmptyFile = TRUE;
  8442. break;
  8443. }
  8444. else
  8445. {
  8446. isEmptyFile = FALSE;
  8447. break;
  8448. }
  8449. }
  8450. }
  8451. else
  8452. isEmptyFile = TRUE;
  8453. fclose(fptr1);
  8454. if(isEmptyFile == TRUE)
  8455. {
  8456. memset(str, 0, ARRAY_SIZE(str));
  8457. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8458. system(str);
  8459. }
  8460. }
  8461. }// End of while(int k=0; k < ChargePointCount; k++)
  8462. }
  8463. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8464. {
  8465. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8466. for(int k=0; k < ChargeProfileCount; k++)
  8467. {
  8468. fptr1 = fopen(chargingProfiles[k], "r");
  8469. fptr2 = fopen(temp, "w+");
  8470. //Check Charging Profile Count
  8471. while(fscanf(fptr1, "%s", word) != EOF)
  8472. {
  8473. //DEBUG_INFO("word=%s\n",word);
  8474. if(strstr(word, "chargingProfileId")!= NULL)
  8475. {
  8476. n_chargingProfile = n_chargingProfile + 1;
  8477. }
  8478. }
  8479. rewind(fptr1);
  8480. //search Charging Profile Element
  8481. //int i= 0;
  8482. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8483. {
  8484. json_object *tmpProfilee;
  8485. tmpProfilee = json_tokener_parse(sLineWord);
  8486. if(!is_error(tmpProfilee))
  8487. {
  8488. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8489. {
  8490. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8491. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8492. }
  8493. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8494. {
  8495. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8496. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8497. }
  8498. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8499. {
  8500. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8501. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8502. }
  8503. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8504. {
  8505. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8506. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8507. }
  8508. }
  8509. json_object_put(tmpProfilee);
  8510. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8511. {
  8512. //------- not write to fptr2-------//
  8513. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8514. //clearflag = TRUE;
  8515. }
  8516. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8517. {
  8518. //------- not write to fptr2-------//
  8519. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8520. }
  8521. else if(stackLevelIsNULL == TRUE)
  8522. {
  8523. //Clear Whole File
  8524. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8525. clearflag = TRUE;
  8526. break;
  8527. }
  8528. else
  8529. {
  8530. fprintf(fptr2, sLineWord);//writing data into file
  8531. }
  8532. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8533. }
  8534. if(clearflag == TRUE)
  8535. {
  8536. fclose(fptr1);
  8537. fclose(fptr2);
  8538. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8539. system(str);
  8540. // clear temp file
  8541. sprintf(str,"rm -f %s",temp);
  8542. system(str);
  8543. }
  8544. else
  8545. {
  8546. fclose(fptr1);
  8547. fclose(fptr2);
  8548. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8549. system(str);
  8550. resultRename = rename(temp, chargingProfiles[k]);
  8551. if(resultRename == 0)
  8552. {
  8553. DEBUG_INFO("File ChargingProfile renamed successfully");
  8554. }
  8555. else
  8556. {
  8557. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8558. }
  8559. if(comfirmstr[0]== 0)
  8560. {
  8561. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8562. }
  8563. //Check chargingProfile is empty file
  8564. /*------ Read the file ----------------*/
  8565. fptr1=fopen(chargingProfiles[k],"r");
  8566. ch=fgetc(fptr1);
  8567. rewind(fptr1);
  8568. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8569. if(ch!=EOF)
  8570. {
  8571. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8572. {
  8573. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8574. if(sLineWord[0]=='\0')
  8575. {
  8576. isEmptyFile = TRUE;
  8577. break;
  8578. }
  8579. else
  8580. {
  8581. isEmptyFile = FALSE;
  8582. break;
  8583. }
  8584. }
  8585. }
  8586. else
  8587. isEmptyFile = TRUE;
  8588. fclose(fptr1);
  8589. if(isEmptyFile == TRUE)
  8590. {
  8591. memset(str, 0, ARRAY_SIZE(str));
  8592. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8593. system(str);
  8594. }
  8595. /*------- End of reading ---------------*/
  8596. }
  8597. } // while(int k=0; k < ChargeProfileCount; k++)
  8598. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8599. end:
  8600. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8601. {
  8602. if(connectorIdInt == 0)
  8603. {
  8604. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8605. {
  8606. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8607. }
  8608. }
  8609. else
  8610. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8611. }
  8612. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8613. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8614. return result;
  8615. }
  8616. void createFirmwareVersionByDataTransfer(void)
  8617. {
  8618. json_object *FirmwareDataTransfer = json_object_new_object();
  8619. // AC & DC model
  8620. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8621. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8622. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8623. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8624. // DC model
  8625. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8626. {
  8627. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8628. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8629. (gunType[3] != GUN_TYPE_UNKNOWN))
  8630. {
  8631. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8632. }
  8633. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8634. {
  8635. // DS DM DW
  8636. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8637. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8638. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8639. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8640. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8641. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8642. }
  8643. else
  8644. {
  8645. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8646. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8647. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8648. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8649. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8650. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8651. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8652. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8653. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8654. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8655. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8656. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8657. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8658. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8659. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8660. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8661. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8663. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8665. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8667. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8669. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8670. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8671. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8672. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8673. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8674. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8675. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8676. }
  8677. }
  8678. // 4G model
  8679. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8680. {
  8681. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8682. }
  8683. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8684. json_object_put(FirmwareDataTransfer);
  8685. }
  8686. int handleDataTransferRequest(char *uuid, char *payload)
  8687. {
  8688. mtrace();
  8689. json_object *response = json_object_new_object();
  8690. int result = FAIL;
  8691. char tempvendorId[255]={0};
  8692. char tempmessageId[50]={0};
  8693. char tempdata[512]={0};
  8694. char message[2048]={0};
  8695. DEBUG_INFO("handleDataTransferRequest...\n");
  8696. if((uuid != NULL) && (payload != NULL))
  8697. {
  8698. json_object *DataTransfer;
  8699. DataTransfer = json_tokener_parse(payload);
  8700. if(!is_error(DataTransfer))
  8701. {
  8702. // Required data
  8703. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8704. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8705. // Optional data
  8706. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8707. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8708. if(json_object_object_get(DataTransfer, "data") != NULL)
  8709. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8710. result = PASS;
  8711. }
  8712. json_object_put(DataTransfer);
  8713. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8714. {
  8715. // Send all moudle firmware version on EVSE
  8716. createFirmwareVersionByDataTransfer();
  8717. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8718. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8719. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8720. json_object_put(response);
  8721. }
  8722. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8723. {
  8724. system("/usr/bin/run_tmate_restart.sh &");
  8725. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8726. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8727. json_object_put(response);
  8728. }
  8729. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8730. {
  8731. json_object *data;
  8732. data = json_tokener_parse(tempdata);
  8733. if(!is_error(data))
  8734. {
  8735. 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))
  8736. {
  8737. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8738. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8739. if(json_object_object_get(data, "SOC") != NULL)
  8740. {
  8741. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8742. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8743. }
  8744. if(json_object_object_get(data, "Energy") != NULL)
  8745. {
  8746. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8747. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8748. }
  8749. if(json_object_object_get(data, "Duration") != NULL)
  8750. {
  8751. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8752. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8753. }
  8754. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8755. }
  8756. else
  8757. {
  8758. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8759. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8760. }
  8761. }
  8762. else
  8763. {
  8764. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8765. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8766. }
  8767. json_object_put(data);
  8768. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8769. json_object_put(response);
  8770. }
  8771. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8772. {
  8773. json_object *data;
  8774. data = json_tokener_parse(tempdata);
  8775. if(!is_error(data))
  8776. {
  8777. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8778. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8779. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8780. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8781. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8782. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8783. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8784. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8785. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8786. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8787. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8788. }
  8789. else
  8790. {
  8791. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8792. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8793. }
  8794. json_object_put(data);
  8795. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8796. json_object_put(response);
  8797. }
  8798. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8799. {
  8800. json_object *data;
  8801. data = json_tokener_parse(tempdata);
  8802. if(!is_error(data))
  8803. {
  8804. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8805. if(json_object_object_get(data, "idToken") != NULL)
  8806. {
  8807. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8808. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8809. }
  8810. if(json_object_object_get(data, "price") != NULL)
  8811. {
  8812. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8813. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8814. }
  8815. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8816. }
  8817. else
  8818. {
  8819. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8820. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8821. }
  8822. json_object_put(data);
  8823. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8824. json_object_put(response);
  8825. }
  8826. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8827. {
  8828. json_object *data;
  8829. data = json_tokener_parse(tempdata);
  8830. if(!is_error(data))
  8831. {
  8832. if(json_object_object_get(data, "txId") != NULL)
  8833. {
  8834. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8835. for(int idx = 0;idx<gunTotalNumber;idx++)
  8836. {
  8837. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8838. {
  8839. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8840. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8841. if(json_object_object_get(data, "description") != NULL)
  8842. {
  8843. // California pricing V1.0
  8844. DEBUG_INFO("California pricing V1.0\n");
  8845. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8846. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8847. }
  8848. else
  8849. {
  8850. // California pricing V1.1
  8851. DEBUG_INFO("California pricing V1.1\n");
  8852. if(json_object_object_get(data, "timestamp") != NULL)
  8853. {
  8854. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8855. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8856. }
  8857. if(json_object_object_get(data, "meterValue") != NULL)
  8858. {
  8859. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8860. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8861. }
  8862. if(json_object_object_get(data, "cost") != NULL)
  8863. {
  8864. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8865. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8866. }
  8867. if(json_object_object_get(data, "state") != NULL)
  8868. {
  8869. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8870. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8871. }
  8872. if(json_object_object_get(data, "chargingPrice") != NULL)
  8873. {
  8874. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8875. {
  8876. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8877. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8878. }
  8879. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8880. {
  8881. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8882. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8883. }
  8884. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8885. {
  8886. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8887. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8888. }
  8889. }
  8890. if(json_object_object_get(data, "idlePrice") != NULL)
  8891. {
  8892. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8893. {
  8894. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8895. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8896. }
  8897. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8898. {
  8899. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8900. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8901. }
  8902. }
  8903. if(json_object_object_get(data, "nextPeriod") != NULL)
  8904. {
  8905. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8906. {
  8907. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8908. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8909. }
  8910. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8911. {
  8912. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8913. {
  8914. 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")));
  8915. 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"));
  8916. }
  8917. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8918. {
  8919. 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")));
  8920. 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"));
  8921. }
  8922. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8923. {
  8924. 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")));
  8925. 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"));
  8926. }
  8927. }
  8928. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8929. {
  8930. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8931. {
  8932. 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")));
  8933. 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"));
  8934. }
  8935. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8936. {
  8937. 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")));
  8938. 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"));
  8939. }
  8940. }
  8941. }
  8942. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8943. {
  8944. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8945. {
  8946. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8947. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8948. }
  8949. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8950. {
  8951. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8952. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8953. }
  8954. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8955. {
  8956. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8957. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8958. }
  8959. }
  8960. }
  8961. }
  8962. }
  8963. }
  8964. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8965. }
  8966. else
  8967. {
  8968. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8969. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8970. }
  8971. json_object_put(data);
  8972. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8973. json_object_put(response);
  8974. }
  8975. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8976. {
  8977. json_object *data;
  8978. data = json_tokener_parse(tempdata);
  8979. if(!is_error(data))
  8980. {
  8981. if(json_object_object_get(data, "txId") != NULL)
  8982. {
  8983. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8984. for(int idx = 0;idx<gunTotalNumber;idx++)
  8985. {
  8986. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8987. {
  8988. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8989. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8990. if(json_object_object_get(data, "description") != NULL)
  8991. {
  8992. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8993. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8994. }
  8995. }
  8996. }
  8997. }
  8998. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8999. }
  9000. else
  9001. {
  9002. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9003. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9004. }
  9005. json_object_put(data);
  9006. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9007. json_object_put(response);
  9008. }
  9009. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9010. {
  9011. json_object *data;
  9012. data = json_tokener_parse(tempdata);
  9013. if(!is_error(data))
  9014. {
  9015. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9016. if(json_object_object_get(data, "Content_Type") != NULL)
  9017. {
  9018. 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))
  9019. {
  9020. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9021. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9022. {
  9023. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9024. }
  9025. }
  9026. else
  9027. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9028. }
  9029. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9030. }
  9031. else
  9032. {
  9033. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9034. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9035. }
  9036. json_object_put(data);
  9037. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9038. json_object_put(response);
  9039. }
  9040. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9041. {
  9042. json_object *data;
  9043. data = json_tokener_parse(tempdata);
  9044. if(!is_error(data))
  9045. {
  9046. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9047. if(json_object_object_get(data, "ConnectorId") != NULL)
  9048. {
  9049. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9050. }
  9051. if(json_object_object_get(data, "SerialNo") != NULL)
  9052. {
  9053. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.LineStatusPage.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9054. }
  9055. if(json_object_object_get(data, "Page_Index") != NULL)
  9056. {
  9057. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9058. }
  9059. if(json_object_object_get(data, "Duration") != NULL)
  9060. {
  9061. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9062. }
  9063. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9064. }
  9065. else
  9066. {
  9067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9068. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9069. }
  9070. json_object_put(data);
  9071. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9072. json_object_put(response);
  9073. }
  9074. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9075. {
  9076. json_object *data;
  9077. data = json_tokener_parse(tempdata);
  9078. if(!is_error(data))
  9079. {
  9080. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9081. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9082. {
  9083. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9084. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9085. else
  9086. {
  9087. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9088. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9089. }
  9090. }
  9091. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9092. {
  9093. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9094. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9095. else
  9096. {
  9097. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9098. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9099. }
  9100. }
  9101. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9102. {
  9103. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9104. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9105. else
  9106. {
  9107. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9108. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9109. }
  9110. }
  9111. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9112. {
  9113. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9114. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9115. else
  9116. {
  9117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9118. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9119. }
  9120. }
  9121. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9122. {
  9123. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9124. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9125. else
  9126. {
  9127. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9128. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9129. }
  9130. }
  9131. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9132. {
  9133. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9134. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9135. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9136. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9137. else
  9138. {
  9139. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9140. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9141. }
  9142. }
  9143. if(json_object_object_get(data, "isAuthentication") != NULL)
  9144. {
  9145. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9146. {
  9147. case 0:
  9148. case 1:
  9149. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9150. break;
  9151. default:
  9152. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9153. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9154. break;
  9155. }
  9156. }
  9157. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9158. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9159. }
  9160. else
  9161. {
  9162. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9163. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9164. }
  9165. json_object_put(data);
  9166. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9167. json_object_put(response);
  9168. }
  9169. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9170. {
  9171. json_object *data;
  9172. data = json_tokener_parse(tempdata);
  9173. if(!is_error(data))
  9174. {
  9175. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9176. if(json_object_object_get(data, "stationName") != NULL)
  9177. {
  9178. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9179. }
  9180. else
  9181. {
  9182. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9183. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9184. }
  9185. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9186. {
  9187. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9188. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9189. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9190. }
  9191. }
  9192. else
  9193. {
  9194. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9195. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9196. }
  9197. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9198. json_object_put(response);
  9199. }
  9200. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9201. {
  9202. json_object *data;
  9203. data = json_tokener_parse(tempdata);
  9204. if(!is_error(data))
  9205. {
  9206. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9207. if(json_object_object_get(data, "weatherId") != NULL)
  9208. {
  9209. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9210. }
  9211. else
  9212. {
  9213. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9214. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9215. }
  9216. if(json_object_object_get(data, "Temperature") != NULL)
  9217. {
  9218. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9219. }
  9220. else
  9221. {
  9222. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9223. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9224. }
  9225. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9226. {
  9227. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9228. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9229. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9230. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9231. }
  9232. }
  9233. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9234. {
  9235. json_object *data;
  9236. data = json_tokener_parse(tempdata);
  9237. if(!is_error(data))
  9238. {
  9239. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9240. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9241. {
  9242. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9243. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9244. }
  9245. else
  9246. {
  9247. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9248. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9249. }
  9250. }
  9251. else
  9252. {
  9253. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9254. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9255. }
  9256. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9257. json_object_put(response);
  9258. }
  9259. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9260. {
  9261. json_object *data;
  9262. data = json_tokener_parse(tempdata);
  9263. if(!is_error(data))
  9264. {
  9265. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9266. {
  9267. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9268. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9269. if(gun_index < gunTotalNumber)
  9270. {
  9271. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9272. {
  9273. json_object *responsedata = json_object_new_object();
  9274. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9275. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9276. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.LineStatusPage.SerialNo[gun_index]));
  9277. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9278. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9279. }
  9280. else
  9281. {
  9282. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9283. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9284. }
  9285. }
  9286. else
  9287. {
  9288. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9289. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9290. }
  9291. }
  9292. else
  9293. {
  9294. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9295. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9296. }
  9297. }
  9298. else
  9299. {
  9300. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9301. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9302. }
  9303. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9304. json_object_put(response);
  9305. }
  9306. else
  9307. {
  9308. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9309. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9310. }
  9311. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9312. json_object_put(response);
  9313. }
  9314. else
  9315. {
  9316. // Can not find valid message id
  9317. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9318. }
  9319. }
  9320. else
  9321. {
  9322. // Payload is null
  9323. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9324. }
  9325. LWS_Send(message);
  9326. return result;
  9327. }
  9328. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9329. {
  9330. mtrace();
  9331. int result = FAIL;
  9332. int connectorIdInt, durationInt;
  9333. char chargingRateUnitStr[4]={0};
  9334. char comfirmstr[20];
  9335. int confirmPeriods = 0;
  9336. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9337. json_object *GetCompositeSchedule;
  9338. GetCompositeSchedule = json_tokener_parse(payload);
  9339. if(!is_error(GetCompositeSchedule))
  9340. {
  9341. // Required data
  9342. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9343. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9344. else
  9345. connectorIdInt = -1;
  9346. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9347. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9348. else
  9349. durationInt = 86400;
  9350. // Optional data
  9351. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9352. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9353. }
  9354. json_object_put(GetCompositeSchedule);
  9355. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9356. if((connectorIdInt == 0) ||
  9357. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9358. {
  9359. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9360. struct StructChargingProfile tmpProfile[1];
  9361. if(strstr(chargingRateUnitStr, "W") != NULL)
  9362. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9363. else
  9364. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9365. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9366. {
  9367. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9368. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9369. }
  9370. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9371. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9372. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9373. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9374. {
  9375. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9376. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9377. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9378. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9379. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9380. {
  9381. confirmPeriods = idx;
  9382. break;
  9383. }
  9384. }
  9385. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9386. {
  9387. confirmPeriods += 1;
  9388. }
  9389. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9390. }
  9391. else
  9392. {
  9393. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9394. }
  9395. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9396. return result;
  9397. }
  9398. int handleGetConfigurationRequest(char *uuid, char *payload)
  9399. {
  9400. mtrace();
  9401. int result = FAIL;
  9402. int MaxKeySupported = 0;
  9403. int n_keys = 0;
  9404. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9405. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9406. json_object *GetConfiguration;
  9407. GetConfiguration = json_tokener_parse(payload);
  9408. if(!is_error(GetConfiguration))
  9409. {
  9410. // Optional data
  9411. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9412. {
  9413. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9414. {
  9415. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9416. n_keys = idx + 1;
  9417. }
  9418. }
  9419. }
  9420. json_object_put(GetConfiguration);
  9421. UnknownKeynum = 0;
  9422. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9423. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9424. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9425. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9426. if(n_keys != 0)
  9427. {
  9428. for(int i=0;i<n_keys;i++)
  9429. {
  9430. getKeyValue(requestKey[i]);
  9431. }
  9432. }
  9433. else
  9434. {
  9435. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9436. getKeyValue("");
  9437. }
  9438. processUnkownKey();
  9439. sendGetConfigurationConfirmation(uuid);
  9440. return result;
  9441. }
  9442. static char fnamePlusPath[100]={0};
  9443. static char fnamePWithNoPath[60]={0};
  9444. void checkUploadLog(void)
  9445. {
  9446. FILE *fp;
  9447. /* Open the command for reading. */
  9448. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9449. if (fp == NULL) {
  9450. DEBUG_WARN("Failed to run command\n" );
  9451. exit(1);
  9452. }
  9453. int ftppathlen = 0;
  9454. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9455. int i = 0;
  9456. /* Read the output a line at a time - output it. */
  9457. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9458. if(i==0)
  9459. {
  9460. ftppathlen = strlen(fnamePlusPath);
  9461. DEBUG_INFO("%s\n", fnamePlusPath);
  9462. fnamePlusPath[ftppathlen]='\0';
  9463. break;
  9464. }
  9465. i= i+1;
  9466. }
  9467. /* close */
  9468. pclose(fp);
  9469. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9470. {
  9471. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9472. {
  9473. fnamePlusPath[k]='\0';
  9474. }
  9475. }
  9476. i=1;
  9477. //char fname[60]={0};
  9478. while(i < ftppathlen)
  9479. {
  9480. int len=ftppathlen-i;
  9481. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9482. {
  9483. DEBUG_INFO("compare '/' all right\n");
  9484. break;
  9485. }
  9486. i=i+1;
  9487. }
  9488. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9489. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9490. fnamePWithNoPath[i+1] = '\0';
  9491. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9492. {
  9493. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9494. {
  9495. fnamePWithNoPath[j]='\0';
  9496. }
  9497. }
  9498. FILE* fp1 = fopen(fnamePlusPath, "r");
  9499. if (fp1)
  9500. {
  9501. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9502. // file exists
  9503. fclose(fp1);
  9504. }
  9505. else
  9506. {
  9507. // file doesn't exist
  9508. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9509. }
  9510. }
  9511. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9512. {
  9513. mtrace();
  9514. int result = FAIL;
  9515. time_t CurrentTime;
  9516. struct tm *tm;
  9517. pthread_t th_Status;
  9518. CurrentTime = time(NULL);
  9519. tm = localtime(&CurrentTime);
  9520. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9521. 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);
  9522. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9523. if(!interLock.isGetDiagnosticGoing)
  9524. {
  9525. interLock.isGetDiagnosticGoing = 1;
  9526. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9527. sleep(1);
  9528. }
  9529. else
  9530. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9531. return result;
  9532. }
  9533. void* GetDiagnosticsProcess(void* data)
  9534. {
  9535. pthread_detach(pthread_self());
  9536. mtrace();
  9537. int retriesInt=0, retryIntervalInt=0;
  9538. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9539. 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};
  9540. int port=0;
  9541. int isSuccess = FALSE;
  9542. char ftpbuf[200]={0};
  9543. char cmdBuf[2048];
  9544. struct tm *tmNow;
  9545. time_t CurrentTime;
  9546. struct tm tmStart;
  9547. struct tm tmStop;
  9548. CurrentTime = time(NULL);
  9549. tmNow=localtime(&CurrentTime);
  9550. uint16_t targetYear, targetMonth;
  9551. json_object *GetDiagnostics;
  9552. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9553. GetDiagnostics = json_tokener_parse(data);
  9554. if(!is_error(GetDiagnostics))
  9555. {
  9556. // Required data
  9557. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9558. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9559. // Optional data
  9560. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9561. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9562. else
  9563. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9564. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9565. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9566. else
  9567. retryIntervalInt = 30;
  9568. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9569. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9570. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9571. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9572. }
  9573. json_object_put(GetDiagnostics);
  9574. // Pack log to compress file
  9575. 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) &&
  9576. (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))
  9577. {
  9578. // Pack system log
  9579. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9580. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9581. targetYear = tmStart.tm_year;
  9582. targetMonth = tmStart.tm_mon;
  9583. do
  9584. {
  9585. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9586. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9587. if(targetMonth+1>=13)
  9588. {
  9589. targetYear += 1;
  9590. targetMonth = 1;
  9591. }
  9592. else
  9593. {
  9594. targetMonth += 1;
  9595. }
  9596. }while((targetYear < (tmNow->tm_year+1900)) ||
  9597. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9598. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9599. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9600. system(cmdBuf);
  9601. // Pack charging & event log
  9602. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9603. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9604. targetYear = tmStart.tm_year;
  9605. targetMonth = tmStart.tm_mon;
  9606. do
  9607. {
  9608. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9609. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9610. if(targetMonth+1>=13)
  9611. {
  9612. targetYear += 1;
  9613. targetMonth = 1;
  9614. }
  9615. else
  9616. {
  9617. targetMonth += 1;
  9618. }
  9619. }while((targetYear < (tmNow->tm_year+1900)) ||
  9620. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9621. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9622. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9623. system(cmdBuf);
  9624. // Combine log file
  9625. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9626. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9627. }
  9628. else
  9629. {
  9630. system("exec /root/logPackTools 'log' 6");
  9631. }
  9632. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9633. system(cmdBuf);
  9634. checkUploadLog();
  9635. //****************location*******************/
  9636. if(strcmp(locationstr,"")==0)
  9637. {
  9638. DEBUG_INFO("location is <Empty>!\n");
  9639. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9640. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9641. goto end;
  9642. }
  9643. memset(protocol, 0, ARRAY_SIZE(protocol));
  9644. memset(user, 0, ARRAY_SIZE(user) );
  9645. memset(password, 0, ARRAY_SIZE(password));
  9646. memset(host, 0, ARRAY_SIZE(host));
  9647. memset(path, 0, ARRAY_SIZE(path));
  9648. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9649. memset(host1, 0, ARRAY_SIZE(host1));
  9650. memset(path1, 0, ARRAY_SIZE(path1));
  9651. /*location: ftp://user:password@host:port/path*/
  9652. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9653. if((access(fnamePlusPath,F_OK))!=-1)
  9654. {
  9655. DEBUG_INFO("fnamePlusPath exist.\n");
  9656. }
  9657. else
  9658. {
  9659. DEBUG_INFO("fnamePlusPath not exist!\n");
  9660. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9661. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9662. goto end;
  9663. }
  9664. if(strchr(locationstr,'@')==NULL)
  9665. {
  9666. sscanf(locationstr,
  9667. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9668. protocol, host, &port, path);
  9669. strcpy(user,"anonymous");
  9670. strcpy(password,"");
  9671. }
  9672. else
  9673. {
  9674. //DEBUG_INFO("pch=%s\n", pch);
  9675. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9676. protocol, user, password, host, &port, path);
  9677. }
  9678. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9679. {
  9680. DEBUG_INFO("protocol is not ftp/http ! \n");
  9681. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9682. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9683. goto end;
  9684. }
  9685. if(strncmp(locationstr,"http", 4) == 0)
  9686. {
  9687. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9688. sprintf(ftppath,"/%s", path);
  9689. do
  9690. {
  9691. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9692. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9693. sleep(3);
  9694. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9695. if(!isSuccess)
  9696. {
  9697. DEBUG_INFO("Diagnostics fail.\n");
  9698. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9699. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9700. sleep(retryIntervalInt);
  9701. }
  9702. else
  9703. {
  9704. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9705. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9706. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9707. }
  9708. retriesInt--;
  9709. }while((isSuccess == 0)&&(retriesInt >= 0));
  9710. }
  9711. else
  9712. {
  9713. sscanf(host,"%[^/]%s",host1, path1);
  9714. if(strlen(path) > 0)
  9715. sprintf(ftppath,"/%s", path);
  9716. else
  9717. sprintf(ftppath,"/%s", path1);
  9718. int ftppathlen=strlen(ftppath);
  9719. int i=1;
  9720. char filenametemp[50];
  9721. while(i < ftppathlen)
  9722. {
  9723. int len=ftppathlen-i;
  9724. if(ftppath[len]== 47) // '/' ascll code: 47
  9725. {
  9726. DEBUG_INFO("find '/' all right\n");
  9727. break;
  9728. }
  9729. i=i+1;
  9730. }
  9731. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9732. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9733. filenametemp[i+1] = 0;
  9734. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9735. if(port == 0)
  9736. port = 21;
  9737. do
  9738. {
  9739. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9740. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9741. sleep(3);
  9742. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9743. if(!isSuccess)
  9744. {
  9745. DEBUG_INFO("Diagnostics fail.\n");
  9746. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9747. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9748. sleep(retryIntervalInt);
  9749. }
  9750. else
  9751. {
  9752. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9753. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9754. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9755. }
  9756. retriesInt--;
  9757. }while((!isSuccess)&&(retriesInt >= 0));
  9758. }
  9759. end:
  9760. system("rm -f /mnt/*");
  9761. sleep(5);
  9762. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9763. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9764. interLock.isGetDiagnosticGoing = 0;
  9765. pthread_exit(NULL);
  9766. }
  9767. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9768. {
  9769. mtrace();
  9770. int result = FAIL;
  9771. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9772. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9773. {
  9774. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9775. locallistVersion = -1;
  9776. }
  9777. else
  9778. {
  9779. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9780. OCPP_getListVerion();
  9781. }
  9782. //from db.OCPP_getListVerion
  9783. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9784. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9785. sendGetLocalListVersionConfirmation(uuid,"");
  9786. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9787. return result;
  9788. }
  9789. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9790. {
  9791. mtrace();
  9792. int result = FAIL;
  9793. int connectorIdInt=-1;
  9794. int tempIndex = 0;
  9795. int connectorIdIsNULL, chargingProfileIsNULL;
  9796. char comfirmstr[20]={0};
  9797. char cmdBuf[512];
  9798. json_object *RemoteStartTransaction;
  9799. FILE *fp;
  9800. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9801. if(server_pending == TRUE)
  9802. {
  9803. return 0;
  9804. }
  9805. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9806. RemoteStartTransaction = json_tokener_parse(payload);
  9807. if(!is_error(RemoteStartTransaction))
  9808. {
  9809. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9810. {
  9811. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9812. }
  9813. else
  9814. {
  9815. connectorIdIsNULL = TRUE;
  9816. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9817. {
  9818. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9819. {
  9820. connectorIdIsNULL = FALSE;
  9821. connectorIdInt = (gun_index+1);
  9822. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9823. break;
  9824. }
  9825. }
  9826. }
  9827. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9828. {
  9829. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9830. // Required data
  9831. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9832. // Optional data
  9833. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9834. {
  9835. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9836. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9837. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9838. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9839. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9840. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9841. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9842. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9843. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9844. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9845. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9846. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9847. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9848. {
  9849. 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")));
  9850. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9851. 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"));
  9852. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9853. 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"));
  9854. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9855. 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")));
  9856. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9857. {
  9858. 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++)
  9859. {
  9860. 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"));
  9861. 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"));
  9862. 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)
  9863. 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"));
  9864. }
  9865. }
  9866. }
  9867. }
  9868. else
  9869. {
  9870. chargingProfileIsNULL = TRUE;
  9871. }
  9872. }
  9873. }
  9874. else
  9875. {
  9876. connectorIdIsNULL = TRUE;
  9877. }
  9878. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9879. {
  9880. DEBUG_WARN("Connector id is NULL\n.");
  9881. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9882. goto end;
  9883. }
  9884. /*
  9885. enum _SYSTEM_STATUS
  9886. {
  9887. S_BOOTING = 0,
  9888. S_IDLE, = 1
  9889. S_AUTHORIZING, = 2
  9890. S_REASSIGN_CHECK, = 3
  9891. S_REASSIGN, = 4
  9892. S_PRECHARGE, = 5
  9893. S_PREPARING_FOR_EV, = 6
  9894. S_PREPARING_FOR_EVSE, = 7
  9895. S_CHARGING, = 8
  9896. S_TERMINATING, = 9
  9897. S_COMPLETE, = 10
  9898. S_ALARM, = 11
  9899. S_FAULT = 12
  9900. }
  9901. */
  9902. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9903. {
  9904. //check Transaction active
  9905. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9906. {
  9907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9908. {
  9909. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9910. }
  9911. else
  9912. {
  9913. tempIndex = connectorIdInt -1;
  9914. }
  9915. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9916. {
  9917. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9918. {
  9919. 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))
  9920. {
  9921. //Reserved
  9922. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9923. }
  9924. 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))
  9925. {
  9926. //Reserved
  9927. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9928. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9929. goto end;
  9930. }
  9931. else
  9932. {
  9933. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9934. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9935. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9936. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9937. {
  9938. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9939. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9940. goto end;
  9941. }
  9942. }//END FOR ELSE
  9943. }
  9944. }// END FOR CHAdeMO_QUANTITY
  9945. }
  9946. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9947. {
  9948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9949. {
  9950. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9951. }
  9952. else
  9953. {
  9954. tempIndex = connectorIdInt -1;
  9955. }
  9956. for (int index = 0; index < CCS_QUANTITY; index++)
  9957. {
  9958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9959. {
  9960. 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))
  9961. {
  9962. //Reserved
  9963. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9964. }
  9965. 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))
  9966. {
  9967. //Reserved
  9968. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9969. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9970. goto end;
  9971. }
  9972. else
  9973. {
  9974. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9975. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9976. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9977. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9978. {
  9979. DEBUG_WARN("CCS connector not allow start\n.");
  9980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9981. goto end;
  9982. }
  9983. }// END FOR ELSE
  9984. }
  9985. }// END FOR CCS_QUANTITY
  9986. }
  9987. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9988. {
  9989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9990. {
  9991. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9992. }
  9993. else
  9994. {
  9995. tempIndex = connectorIdInt -1;
  9996. }
  9997. for (int index = 0; index < GB_QUANTITY; index++)
  9998. {
  9999. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10000. {
  10001. 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))
  10002. {
  10003. //Reserved
  10004. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10005. }
  10006. 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))
  10007. {
  10008. //Reserved
  10009. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10010. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10011. goto end;
  10012. }
  10013. else
  10014. {
  10015. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10016. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10017. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10018. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10019. {
  10020. DEBUG_WARN("GB connector not allow start\n.");
  10021. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10022. goto end;
  10023. }
  10024. }// END FOR ELSE
  10025. }
  10026. } // END FOR GB_QUANTITY
  10027. }
  10028. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10029. {
  10030. tempIndex = connectorIdInt -1;
  10031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10032. {
  10033. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10034. {
  10035. 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))
  10036. {
  10037. //Reserved
  10038. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10039. }
  10040. 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))
  10041. {
  10042. //Reserved
  10043. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10044. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10045. goto end;
  10046. }
  10047. else
  10048. {
  10049. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10050. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10051. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10052. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10053. {
  10054. DEBUG_WARN("GB connector not allow start\n.");
  10055. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10056. goto end;
  10057. }
  10058. }// END FOR ELSE
  10059. }
  10060. } // END FOR GB_QUANTITY
  10061. }
  10062. else
  10063. {
  10064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10065. {
  10066. tempIndex = 2;
  10067. }
  10068. else
  10069. {
  10070. tempIndex = connectorIdInt -1;
  10071. }
  10072. for (int index = 0; index < AC_QUANTITY; index++)
  10073. {
  10074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10075. {
  10076. 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))
  10077. {
  10078. //Reserved
  10079. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10080. }
  10081. 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))
  10082. {
  10083. //Reserved
  10084. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10086. goto end;
  10087. }
  10088. else
  10089. {
  10090. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10091. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10092. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10093. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10094. {
  10095. DEBUG_WARN("AC connector not allow start\n.");
  10096. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10097. goto end;
  10098. }
  10099. }//END FOR ELSE
  10100. }
  10101. }// END FOR AC_QUANTITY
  10102. }
  10103. if(chargingProfileIsNULL == FALSE)
  10104. {
  10105. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10106. {
  10107. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10109. //memset idTag
  10110. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10111. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10112. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10114. // Save profile to file
  10115. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10116. system(cmdBuf);
  10117. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10118. fp = fopen(cmdBuf, "w");
  10119. 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));
  10120. fclose(fp);
  10121. }
  10122. else
  10123. {
  10124. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10125. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10126. }
  10127. }
  10128. else
  10129. {
  10130. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10132. //memset idTag
  10133. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10134. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10135. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10137. }
  10138. }
  10139. else
  10140. {
  10141. DEBUG_WARN("Connector id over\n.");
  10142. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10143. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10144. }
  10145. end:
  10146. json_object_put(RemoteStartTransaction);
  10147. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10148. {
  10149. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10150. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10151. }
  10152. //OCPP send RemoteStartConfirmation by first.
  10153. sendRemoteStartConfirmation(uuid, comfirmstr);
  10154. return result;
  10155. }
  10156. int handleRemoteStartRequest(char *uuid, char *payload)
  10157. {
  10158. mtrace();
  10159. int result = PASS;
  10160. int connectorIdInt=-1;
  10161. int tempIndex = 0;
  10162. char comfirmstr[20]={0};
  10163. char cmdBuf[512];
  10164. json_object *RemoteStartTransaction;
  10165. FILE *fp;
  10166. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10167. if(server_pending == TRUE)
  10168. {
  10169. result = FAIL;
  10170. }
  10171. RemoteStartTransaction = json_tokener_parse(payload);
  10172. if(!is_error(RemoteStartTransaction))
  10173. {
  10174. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10175. {
  10176. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10177. }
  10178. else
  10179. {
  10180. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10181. {
  10182. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10183. {
  10184. connectorIdInt = (gun_index+1);
  10185. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10186. break;
  10187. }
  10188. }
  10189. }
  10190. if(connectorIdInt == 0)
  10191. {
  10192. DEBUG_WARN("Connector id shall not equal 0.\n");
  10193. result = FAIL;
  10194. }
  10195. else if(connectorIdInt == -1)
  10196. {
  10197. DEBUG_INFO("Connector id does not specific.\n");
  10198. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10199. {
  10200. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10201. // Required data
  10202. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10203. // Optional data
  10204. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10205. {
  10206. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10207. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10208. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10209. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10210. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10211. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10212. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10213. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10214. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10215. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10216. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10217. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10218. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10219. {
  10220. 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")));
  10221. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10222. 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"));
  10223. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10224. 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"));
  10225. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10226. 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")));
  10227. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10228. {
  10229. 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++)
  10230. {
  10231. 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"));
  10232. 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"));
  10233. 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)
  10234. 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"));
  10235. }
  10236. }
  10237. }
  10238. }
  10239. else
  10240. {
  10241. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10242. }
  10243. }
  10244. }
  10245. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10246. {
  10247. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10248. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10249. // Required data
  10250. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10251. // Optional data
  10252. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10253. {
  10254. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10255. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10256. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10257. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10258. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10259. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10260. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10261. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10262. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10263. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10264. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10265. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10266. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10267. {
  10268. 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")));
  10269. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10270. 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"));
  10271. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10272. 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"));
  10273. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10274. 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")));
  10275. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10276. {
  10277. 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++)
  10278. {
  10279. 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"));
  10280. 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"));
  10281. 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)
  10282. 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"));
  10283. }
  10284. }
  10285. }
  10286. }
  10287. else
  10288. {
  10289. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10290. }
  10291. }
  10292. else
  10293. {
  10294. DEBUG_WARN("Connector id is over maximun value.\n");
  10295. result = FAIL;
  10296. }
  10297. }
  10298. if(result == PASS)
  10299. {
  10300. if(connectorIdInt > 0)
  10301. {
  10302. //check Transaction active
  10303. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10304. {
  10305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10306. {
  10307. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10308. }
  10309. else
  10310. {
  10311. tempIndex = connectorIdInt -1;
  10312. }
  10313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10314. {
  10315. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10316. {
  10317. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10318. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10319. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10320. {
  10321. //Reserved
  10322. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10323. }
  10324. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10325. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10326. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10327. {
  10328. //Reserved
  10329. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10330. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10331. goto end;
  10332. }
  10333. else
  10334. {
  10335. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10336. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10337. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10339. {
  10340. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10342. goto end;
  10343. }
  10344. }//END FOR ELSE
  10345. }
  10346. }// END FOR CHAdeMO_QUANTITY
  10347. }
  10348. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10349. {
  10350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10351. {
  10352. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10353. }
  10354. else
  10355. {
  10356. tempIndex = connectorIdInt -1;
  10357. }
  10358. for (int index = 0; index < CCS_QUANTITY; index++)
  10359. {
  10360. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10361. {
  10362. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10363. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10364. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10365. {
  10366. //Reserved
  10367. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10368. }
  10369. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10370. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10371. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10372. {
  10373. //Reserved
  10374. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10375. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10376. goto end;
  10377. }
  10378. else
  10379. {
  10380. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10381. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10382. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10383. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10384. {
  10385. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10386. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10387. goto end;
  10388. }
  10389. }// END FOR ELSE
  10390. }
  10391. }// END FOR CCS_QUANTITY
  10392. }
  10393. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10394. {
  10395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10396. {
  10397. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10398. }
  10399. else
  10400. {
  10401. tempIndex = connectorIdInt -1;
  10402. }
  10403. for (int index = 0; index < GB_QUANTITY; index++)
  10404. {
  10405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10406. {
  10407. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10408. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10409. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10410. {
  10411. //Reserved
  10412. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10413. }
  10414. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10415. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10416. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10417. {
  10418. //Reserved
  10419. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10420. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10421. goto end;
  10422. }
  10423. else
  10424. {
  10425. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10426. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10427. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10429. {
  10430. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10431. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10432. goto end;
  10433. }
  10434. }// END FOR ELSE
  10435. }
  10436. } // END FOR GB_QUANTITY
  10437. }
  10438. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10439. {
  10440. tempIndex = connectorIdInt -1;
  10441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10442. {
  10443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10444. {
  10445. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10446. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10447. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10448. {
  10449. //Reserved
  10450. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10451. }
  10452. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10453. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10454. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10455. {
  10456. //Reserved
  10457. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10458. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10459. goto end;
  10460. }
  10461. else
  10462. {
  10463. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10464. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10465. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10466. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10467. {
  10468. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10469. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10470. goto end;
  10471. }
  10472. }// END FOR ELSE
  10473. }
  10474. } // END FOR GB_QUANTITY
  10475. }
  10476. else
  10477. {
  10478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10479. {
  10480. tempIndex = 2;
  10481. }
  10482. else
  10483. {
  10484. tempIndex = connectorIdInt -1;
  10485. }
  10486. for (int index = 0; index < AC_QUANTITY; index++)
  10487. {
  10488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10489. {
  10490. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10492. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10493. {
  10494. //Reserved
  10495. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10496. }
  10497. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10498. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10499. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10500. {
  10501. //Reserved
  10502. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10503. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10504. goto end;
  10505. }
  10506. else
  10507. {
  10508. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10509. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10510. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10511. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10512. {
  10513. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10515. goto end;
  10516. }
  10517. }//END FOR ELSE
  10518. }
  10519. }// END FOR AC_QUANTITY
  10520. }
  10521. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10522. {
  10523. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10524. {
  10525. // Save profile to file
  10526. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10527. system(cmdBuf);
  10528. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10529. fp = fopen(cmdBuf, "w");
  10530. 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));
  10531. fclose(fp);
  10532. }
  10533. else
  10534. {
  10535. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10536. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10537. goto end;
  10538. }
  10539. }
  10540. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10542. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10543. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10544. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10546. }
  10547. else
  10548. {
  10549. uint8_t isHasIdleConnector = FALSE;
  10550. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10551. {
  10552. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10553. {
  10554. isHasIdleConnector = TRUE;
  10555. break;
  10556. }
  10557. }
  10558. if(isHasIdleConnector == TRUE)
  10559. {
  10560. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10561. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10562. {
  10563. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10564. {
  10565. // Save profile to file
  10566. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10567. system(cmdBuf);
  10568. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10569. fp = fopen(cmdBuf, "w");
  10570. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10571. fclose(fp);
  10572. refreshStartTimer(&clientTime.RemoteStartWait);
  10573. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10574. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10575. }
  10576. else
  10577. {
  10578. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10579. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10580. }
  10581. }
  10582. else
  10583. {
  10584. refreshStartTimer(&clientTime.RemoteStartWait);
  10585. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10586. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10587. }
  10588. }
  10589. else
  10590. {
  10591. DEBUG_INFO("There is not any connector is idle.\n");
  10592. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10593. }
  10594. }
  10595. }
  10596. else
  10597. {
  10598. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10599. }
  10600. end:
  10601. json_object_put(RemoteStartTransaction);
  10602. sendRemoteStartConfirmation(uuid, comfirmstr);
  10603. return result;
  10604. }
  10605. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10606. {
  10607. mtrace();
  10608. int result = FAIL;
  10609. int match = FALSE;
  10610. int GunNO = 0;
  10611. int tempIndex = 0;
  10612. int transactionIdInt=0;
  10613. int transactionIdIsNULL= TRUE;
  10614. char comfirmstr[20];
  10615. json_object *RemoteStopTransaction;
  10616. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10617. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10618. if(server_pending == TRUE)
  10619. {
  10620. return 0;
  10621. }
  10622. RemoteStopTransaction = json_tokener_parse(payload);
  10623. if(!is_error(RemoteStopTransaction))
  10624. {
  10625. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10626. {
  10627. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10628. transactionIdIsNULL = FALSE;
  10629. }
  10630. }
  10631. json_object_put(RemoteStopTransaction);
  10632. if(transactionIdIsNULL == FALSE)
  10633. {
  10634. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10635. {
  10636. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10637. {
  10638. //check Transaction active
  10639. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10640. {
  10641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10642. {
  10643. tempIndex = ((gun_index==2) ? 1: 0);
  10644. }
  10645. else
  10646. {
  10647. tempIndex = gun_index;
  10648. }
  10649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10650. {
  10651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10652. {
  10653. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10654. {
  10655. match = TRUE;
  10656. GunNO = gun_index;
  10657. }
  10658. }
  10659. }// END FOR CHAdeMO_QUANTITY
  10660. }
  10661. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10662. {
  10663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10664. {
  10665. tempIndex = ((gun_index==2) ? 1: 0);
  10666. }
  10667. else
  10668. {
  10669. tempIndex = gun_index;
  10670. }
  10671. for (int index = 0; index < CCS_QUANTITY; index++)
  10672. {
  10673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10674. {
  10675. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10676. {
  10677. match = TRUE;
  10678. GunNO = gun_index;
  10679. }
  10680. }
  10681. }// END FOR CCS_QUANTITY
  10682. }
  10683. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10684. {
  10685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10686. {
  10687. tempIndex = ((gun_index==2) ? 1: 0);
  10688. }
  10689. else
  10690. {
  10691. tempIndex = gun_index;
  10692. }
  10693. for (int index = 0; index < GB_QUANTITY; index++)
  10694. {
  10695. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10696. {
  10697. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10698. {
  10699. match = TRUE;
  10700. GunNO = gun_index;
  10701. }
  10702. }
  10703. }// END FOR GB_QUANTITY
  10704. }
  10705. else if(gunType[gun_index] == GUN_TYPE_DO)
  10706. {
  10707. tempIndex = gun_index;
  10708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10709. {
  10710. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10711. {
  10712. 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
  10713. {
  10714. match = TRUE;
  10715. GunNO = gun_index;
  10716. }
  10717. }
  10718. }// END FOR GB_QUANTITY
  10719. }
  10720. else
  10721. {
  10722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10723. {
  10724. tempIndex = 2;
  10725. }
  10726. else
  10727. {
  10728. tempIndex = gun_index;
  10729. }
  10730. for (int index = 0; index < AC_QUANTITY; index++)
  10731. {
  10732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10733. {
  10734. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10735. {
  10736. match = TRUE;
  10737. GunNO = gun_index;
  10738. }
  10739. }
  10740. }// END FOR CHAdeMO_QUANTITY
  10741. } // END FOR AC ELSE
  10742. }// CHECK IF ResponseTransactionId == transactionIdInt
  10743. }//END FOR
  10744. if( match == TRUE)
  10745. {
  10746. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10748. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10749. }
  10750. else
  10751. {
  10752. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10753. }
  10754. }
  10755. else
  10756. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10757. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10758. return result;
  10759. }
  10760. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10761. {
  10762. mtrace();
  10763. int result = FAIL;
  10764. int connectorIdInt=0, reservationIdInt=0;
  10765. int tempIndex = 0;
  10766. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10767. char comfirmstr[20]={0};
  10768. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10769. int c = 0;
  10770. char *loc;
  10771. //char *ptr;
  10772. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10773. strcpy(sstrtemp, stringtrimspace(payload));
  10774. //***(1)connectorId ****/
  10775. c=0;
  10776. loc = strstr(sstrtemp, "connectorId");
  10777. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10778. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10779. {
  10780. sstr[c] = loc[strlen("connectorId")+2+c];
  10781. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10782. c++;
  10783. }
  10784. sstr[c] = '\0';
  10785. connectorIdInt = atoi(sstr);
  10786. //***(2)expiryDate ****/
  10787. loc = strstr(sstrtemp, "expiryDate");
  10788. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10789. c = 0;
  10790. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10791. {
  10792. sstr[c] = loc[3+strlen("expiryDate")+c];
  10793. c++;
  10794. }
  10795. sstr[c] = '\0';
  10796. strcpy(expiryDatestr, sstr);
  10797. //***(3)idTag ****/
  10798. loc = strstr(sstrtemp, "idTag");
  10799. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10800. c = 0;
  10801. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10802. {
  10803. sstr[c] = loc[3+strlen("idTag")+c];
  10804. c++;
  10805. }
  10806. sstr[c] = '\0';
  10807. strcpy(idTagstr, sstr);
  10808. //***(4)parentIdTag ****/
  10809. loc = strstr(sstrtemp, "parentIdTag");
  10810. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10811. c = 0;
  10812. if(loc == NULL)
  10813. {
  10814. strcpy(parentIdTagstr, "");
  10815. }
  10816. else
  10817. {
  10818. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10819. {
  10820. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10821. c++;
  10822. }
  10823. sstr[c] = '\0';
  10824. strcpy(parentIdTagstr, sstr);
  10825. }
  10826. //***(5)reservationId ****/
  10827. c=0;
  10828. loc = strstr(sstrtemp, "reservationId");
  10829. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10830. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10831. {
  10832. sstr[c] = loc[strlen("reservationId")+2+c];
  10833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10834. c++;
  10835. }
  10836. sstr[c] = '\0';
  10837. reservationIdInt = atoi(sstr);
  10838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10839. /*
  10840. enum SYSTEM_STATUS
  10841. {
  10842. SYS_MODE_BOOTING = 0,
  10843. SYS_MODE_IDLE = 1,
  10844. SYS_MODE_AUTHORIZING = 2,
  10845. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10846. SYS_MODE_REASSIGN = 4,
  10847. SYS_MODE_PREPARING = 5,
  10848. SYS_MODE_PREPARE_FOR_EV = 6,
  10849. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10850. SYS_MODE_CHARGING = 8,
  10851. SYS_MODE_TERMINATING = 9,
  10852. SYS_MODE_COMPLETE = 10,
  10853. SYS_MODE_ALARM = 11,
  10854. SYS_MODE_FAULT = 12,
  10855. SYS_MODE_RESERVATION = 13,
  10856. SYS_MODE_BOOKING = 14,
  10857. SYS_MODE_MAINTAIN = 15,
  10858. SYS_MODE_DEBUG = 16,
  10859. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10860. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10861. SYS_MODE_UPDATE = 19
  10862. };
  10863. */
  10864. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10865. {
  10866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10867. goto end;
  10868. }
  10869. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10870. {
  10871. //check Transaction active
  10872. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10873. {
  10874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10875. {
  10876. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10877. }
  10878. else
  10879. {
  10880. tempIndex = connectorIdInt -1;
  10881. }
  10882. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10883. {
  10884. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10885. {
  10886. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10887. {
  10888. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10889. {
  10890. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10891. {
  10892. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10894. }
  10895. 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'))
  10896. {
  10897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10898. }
  10899. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10900. {
  10901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10902. }
  10903. else
  10904. {
  10905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10906. }
  10907. }
  10908. 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
  10909. {
  10910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10911. }
  10912. }
  10913. else
  10914. {
  10915. //replace reservation
  10916. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10918. }
  10919. }
  10920. } // END FOR CHAdeMO_QUANTITY
  10921. }
  10922. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10923. {
  10924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10925. {
  10926. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10927. }
  10928. else
  10929. {
  10930. tempIndex = connectorIdInt -1;
  10931. }
  10932. for (int index = 0; index < CCS_QUANTITY; index++)
  10933. {
  10934. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10935. {
  10936. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10937. {
  10938. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10939. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10940. {
  10941. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10942. {
  10943. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10945. }
  10946. 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'))
  10947. {
  10948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10949. }
  10950. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10951. {
  10952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10953. }
  10954. else
  10955. {
  10956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10957. }
  10958. }
  10959. 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
  10960. {
  10961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10962. }
  10963. }
  10964. else
  10965. {
  10966. //replace reservation
  10967. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10969. }
  10970. }
  10971. } // END FOR CCS_QUANTITY
  10972. }
  10973. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10974. {
  10975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10976. {
  10977. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10978. }
  10979. else
  10980. {
  10981. tempIndex = connectorIdInt -1;
  10982. }
  10983. for (int index = 0; index < GB_QUANTITY; index++)
  10984. {
  10985. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10986. {
  10987. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10988. {
  10989. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10990. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10991. {
  10992. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10993. {
  10994. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10996. }
  10997. 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'))
  10998. {
  10999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11000. }
  11001. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11002. {
  11003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11004. }
  11005. else
  11006. {
  11007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11008. }
  11009. }
  11010. 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
  11011. {
  11012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11013. }
  11014. }
  11015. else
  11016. {
  11017. //replace reservation
  11018. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11020. }
  11021. }
  11022. }// END FOR GB_QUANTITY
  11023. }
  11024. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11025. {
  11026. tempIndex = connectorIdInt -1;
  11027. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11028. {
  11029. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11030. {
  11031. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11032. {
  11033. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11034. 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
  11035. {
  11036. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11037. {
  11038. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11040. }
  11041. 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'))
  11042. {
  11043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11044. }
  11045. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11046. {
  11047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11048. }
  11049. else
  11050. {
  11051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11052. }
  11053. }
  11054. 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
  11055. {
  11056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11057. }
  11058. }
  11059. else
  11060. {
  11061. //replace reservation
  11062. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11064. }
  11065. }
  11066. }// END FOR GB_QUANTITY
  11067. }
  11068. else
  11069. {
  11070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11071. {
  11072. tempIndex = 2;
  11073. }
  11074. else
  11075. {
  11076. tempIndex = (connectorIdInt -1);
  11077. }
  11078. for (int index = 0; index < AC_QUANTITY; index++)
  11079. {
  11080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11081. {
  11082. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11083. {
  11084. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11085. {
  11086. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11087. {
  11088. 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))
  11089. {
  11090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11091. }
  11092. else
  11093. {
  11094. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11096. }
  11097. }
  11098. 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'))
  11099. {
  11100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11101. }
  11102. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11103. {
  11104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11105. }
  11106. else
  11107. {
  11108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11109. }
  11110. }
  11111. 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
  11112. {
  11113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11114. }
  11115. }
  11116. else
  11117. {
  11118. //replace reservation
  11119. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11121. }
  11122. }
  11123. } // END FOR AC_QUANTITY
  11124. }
  11125. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11126. }
  11127. else if(connectorIdInt == 0)
  11128. {
  11129. //check Transaction active
  11130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11131. {
  11132. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11133. {
  11134. 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'))
  11135. {
  11136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11137. goto end;
  11138. }
  11139. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11140. {
  11141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11142. goto end;
  11143. }
  11144. 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
  11145. {
  11146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11147. goto end;
  11148. }
  11149. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11150. {
  11151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11152. goto end;
  11153. }
  11154. }
  11155. }// END FOR CHAdeMO_QUANTITY
  11156. for (int index = 0; index < CCS_QUANTITY; index++)
  11157. {
  11158. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11159. {
  11160. 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'))
  11161. {
  11162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11163. goto end;
  11164. }
  11165. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11166. {
  11167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11168. goto end;
  11169. }
  11170. 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
  11171. {
  11172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11173. goto end;
  11174. }
  11175. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11176. {
  11177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11178. goto end;
  11179. }
  11180. }
  11181. } // END FOR CCS_QUANTITY
  11182. for (int index = 0; index < GB_QUANTITY; index++)
  11183. {
  11184. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11185. {
  11186. 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'))
  11187. {
  11188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11189. goto end;
  11190. }
  11191. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11192. {
  11193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11194. goto end;
  11195. }
  11196. 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
  11197. {
  11198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11199. goto end;
  11200. }
  11201. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11202. {
  11203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11204. goto end;
  11205. }
  11206. }
  11207. } // END FOR GB_QUANTITY
  11208. for (int index = 0; index < AC_QUANTITY; index++)
  11209. {
  11210. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11211. {
  11212. 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'))
  11213. {
  11214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11215. goto end;
  11216. }
  11217. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11218. {
  11219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11220. goto end;
  11221. }
  11222. 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
  11223. {
  11224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11225. goto end;
  11226. }
  11227. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11228. {
  11229. 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))
  11230. {
  11231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11232. goto end;
  11233. }
  11234. }
  11235. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11236. {
  11237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11238. goto end;
  11239. }
  11240. }
  11241. }// END FOR AC_QUANTITY
  11242. //The connectorId is 0
  11243. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11244. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11245. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11246. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11247. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11248. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11249. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11250. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11251. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11252. result = TRUE;
  11253. return result;
  11254. }
  11255. else
  11256. {
  11257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11258. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11259. }
  11260. if(strcmp(comfirmstr,"Accepted") == 0)
  11261. {
  11262. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11263. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11264. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11265. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11266. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11267. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11268. result = TRUE;
  11269. return result;
  11270. }
  11271. end:
  11272. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11273. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11274. return result;
  11275. }
  11276. int handleResetRequest(char *uuid, char *payload)
  11277. {
  11278. mtrace();
  11279. int result = FAIL;
  11280. char sstr[10]={0},sstrtemp[30]={ 0 };
  11281. char typestr[10]={0};
  11282. char comfirmstr[20]={0};
  11283. int c = 0;
  11284. char *loc;
  11285. DEBUG_INFO("handleResetRequest...\n");
  11286. strcpy(sstrtemp, stringtrimspace(payload));
  11287. loc = strstr(sstrtemp, "type");
  11288. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11289. c = 0;
  11290. while (loc[3+strlen("type")+c] != '\"')
  11291. {
  11292. sstr[c] = loc[3+strlen("type")+c];
  11293. c++;
  11294. }
  11295. sstr[c] = '\0';
  11296. strcpy(typestr,sstr);
  11297. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11298. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11299. {
  11300. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11301. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11302. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11303. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11304. }
  11305. else
  11306. {
  11307. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11308. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11309. result = PASS;
  11310. }
  11311. sendResetConfirmation(uuid, comfirmstr);
  11312. return result;
  11313. }
  11314. int handleSendLocalListRequest(char *uuid, char *payload)
  11315. {
  11316. mtrace();
  11317. int result = FAIL;
  11318. char comfirmstr[20];
  11319. int checkState_Faulted = FALSE;
  11320. json_object *SendLocalList;
  11321. DEBUG_INFO("handleSendLocalListRequest...\n");
  11322. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11323. {
  11324. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11325. goto end;
  11326. }
  11327. //check Charge Point state
  11328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11329. {
  11330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11331. {
  11332. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11333. }
  11334. }
  11335. for (int index = 0; index < CCS_QUANTITY; index++)
  11336. {
  11337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11338. {
  11339. checkState_Faulted = TRUE; //OCPP Status
  11340. }
  11341. }
  11342. for (int index = 0; index < GB_QUANTITY; index++)
  11343. {
  11344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11345. {
  11346. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11347. }
  11348. }
  11349. //check Charge Point state
  11350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11351. {
  11352. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11353. {
  11354. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11355. }
  11356. }
  11357. //check Charge Point state
  11358. for (int index = 0; index < AC_QUANTITY; index++)
  11359. {
  11360. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11361. {
  11362. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11363. }
  11364. }
  11365. if(checkState_Faulted == TRUE)
  11366. {
  11367. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11368. goto end;
  11369. }
  11370. // Parsing payload
  11371. SendLocalList = json_tokener_parse(payload);
  11372. if(!is_error(SendLocalList))
  11373. {
  11374. // Required data
  11375. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11376. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11377. // Optional data
  11378. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11379. {
  11380. //Check UpdateType
  11381. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11382. {
  11383. //Local list full update
  11384. DEBUG_INFO("Local list full update.\n");
  11385. OCPP_getListVerion();
  11386. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11387. {
  11388. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11389. goto end;
  11390. }
  11391. OCPP_cleanLocalList();
  11392. }
  11393. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11394. {
  11395. //Local list different update
  11396. DEBUG_INFO("Local list different update.\n");
  11397. OCPP_getListVerion();
  11398. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11399. {
  11400. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11401. goto end;
  11402. }
  11403. }
  11404. else
  11405. {
  11406. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11407. goto end;
  11408. }
  11409. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11410. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11411. {
  11412. 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")));
  11413. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11414. {
  11415. 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")));
  11416. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11417. 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")));
  11418. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11419. 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")));
  11420. }
  11421. // Add to db
  11422. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11423. {
  11424. //Local list full update
  11425. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11426. idx,
  11427. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11428. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11429. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11430. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11431. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11432. // update list
  11433. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11434. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11435. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11436. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11437. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11438. }
  11439. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11440. {
  11441. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11442. idx,
  11443. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11444. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11445. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11446. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11447. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11448. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11449. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11450. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11451. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11452. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11453. }
  11454. }
  11455. }
  11456. else
  11457. {
  11458. //Check UpdateType
  11459. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11460. {
  11461. //Local list full update
  11462. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11463. OCPP_cleanLocalList();
  11464. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11465. goto end;
  11466. }
  11467. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11468. {
  11469. //Local list different update
  11470. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11471. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11472. goto end;
  11473. }
  11474. }
  11475. result = PASS;
  11476. }
  11477. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11478. end:
  11479. json_object_put(SendLocalList);
  11480. sendSendLocalListConfirmation(uuid, comfirmstr);
  11481. return result;
  11482. }
  11483. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11484. {
  11485. mtrace();
  11486. int result = FAIL;
  11487. struct StructSetChargingProfile SetProfileReq = {0};
  11488. int tempchargingProfileIdInt;
  11489. int chargingSchedulePeriodCount = 0;
  11490. char comfirmstr[20]={0};
  11491. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11492. char rmFileCmd[128]={0};
  11493. int profileQuantity = 0;
  11494. json_object *SetChargingProfile;
  11495. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11496. SetChargingProfile = json_tokener_parse(payload);
  11497. if(!is_error(SetChargingProfile))
  11498. {
  11499. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11500. {
  11501. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11502. }
  11503. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11504. {
  11505. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11506. {
  11507. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11508. }
  11509. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11510. {
  11511. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11512. }
  11513. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11514. {
  11515. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11516. }
  11517. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11518. {
  11519. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11520. }
  11521. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11522. {
  11523. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11524. }
  11525. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11526. {
  11527. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11528. }
  11529. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11530. {
  11531. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11532. }
  11533. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11534. {
  11535. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11536. }
  11537. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11538. {
  11539. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11540. {
  11541. 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")));
  11542. }
  11543. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11544. {
  11545. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11546. }
  11547. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11548. {
  11549. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11550. }
  11551. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11552. {
  11553. 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")));
  11554. }
  11555. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11556. {
  11557. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11558. if(chargingSchedulePeriodCount <= 10)
  11559. {
  11560. 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++)
  11561. {
  11562. 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)
  11563. {
  11564. 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"));
  11565. }
  11566. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  11567. {
  11568. 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"));
  11569. }
  11570. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11571. {
  11572. 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"));
  11573. }
  11574. }
  11575. }
  11576. }
  11577. }
  11578. }
  11579. }
  11580. // Profile periods quantity check
  11581. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11582. {
  11583. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11584. goto end;
  11585. }
  11586. // Check invalid limit
  11587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11588. {
  11589. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11590. {
  11591. 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)))) ||
  11592. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11593. {
  11594. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11595. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11596. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11597. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11598. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11599. goto end;
  11600. }
  11601. }
  11602. }
  11603. else
  11604. {
  11605. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11606. {
  11607. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower))
  11608. {
  11609. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11610. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11611. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11612. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11613. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11614. goto end;
  11615. }
  11616. }
  11617. }
  11618. // Profile purpose info check
  11619. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11620. {
  11621. FILE *fp;
  11622. char dataLine[4096]={0};
  11623. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11624. if(SetProfileReq.ConnectorId != 0)
  11625. {
  11626. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11627. goto end;
  11628. }
  11629. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11630. if (!fp)
  11631. {
  11632. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11633. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11634. }
  11635. else
  11636. {
  11637. while(fscanf(fp, "%s", dataLine) != EOF)
  11638. {
  11639. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11640. {
  11641. profileQuantity += 1;
  11642. }
  11643. }
  11644. }
  11645. fclose(fp);
  11646. }
  11647. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11648. {
  11649. FILE *fp;
  11650. char dataLine[4096]={0};
  11651. char filename[128]={0};
  11652. int tmpProfileQuantity;
  11653. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11654. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11655. {
  11656. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11657. goto end;
  11658. }
  11659. if(SetProfileReq.ConnectorId == 0)
  11660. {
  11661. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11662. {
  11663. tmpProfileQuantity = 0;
  11664. memset(filename, 0, ARRAY_SIZE(filename));
  11665. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11666. fp = fopen(filename, "r");
  11667. if (!fp)
  11668. {
  11669. DEBUG_INFO("%s does not create.\n", filename);
  11670. fp = fopen(filename, "w+");
  11671. }
  11672. else
  11673. {
  11674. while(fscanf(fp, "%s", dataLine) != EOF)
  11675. {
  11676. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11677. {
  11678. tmpProfileQuantity += 1;
  11679. }
  11680. }
  11681. }
  11682. fclose(fp);
  11683. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11684. }
  11685. }
  11686. else
  11687. {
  11688. memset(filename, 0, ARRAY_SIZE(filename));
  11689. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11690. fp = fopen(filename, "r");
  11691. if (!fp)
  11692. {
  11693. DEBUG_INFO("%s does not create.\n", filename);
  11694. fp = fopen(filename, "w+");
  11695. }
  11696. else
  11697. {
  11698. while(fscanf(fp, "%s", dataLine) != EOF)
  11699. {
  11700. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11701. {
  11702. profileQuantity += 1;
  11703. }
  11704. }
  11705. }
  11706. fclose(fp);
  11707. }
  11708. }
  11709. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11710. {
  11711. int isMatchTransactiodId= FALSE;
  11712. FILE *fp;
  11713. char dataLine[4096]={0};
  11714. char filename[128]={0};
  11715. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11716. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11717. if(SetProfileReq.ConnectorId == 0)
  11718. {
  11719. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11720. goto end;
  11721. }
  11722. int tempIndex = 0;
  11723. //check Transaction active
  11724. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11725. {
  11726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11727. {
  11728. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11729. }
  11730. else
  11731. {
  11732. tempIndex = SetProfileReq.ConnectorId -1;
  11733. }
  11734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11735. {
  11736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11737. {
  11738. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11739. {
  11740. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11741. {
  11742. isMatchTransactiodId = TRUE;
  11743. break;
  11744. }
  11745. }
  11746. }
  11747. }
  11748. }
  11749. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11750. {
  11751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11752. {
  11753. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11754. }
  11755. else
  11756. {
  11757. tempIndex = SetProfileReq.ConnectorId -1;
  11758. }
  11759. for (int index = 0; index < CCS_QUANTITY; index++)
  11760. {
  11761. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11762. {
  11763. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11764. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11765. {
  11766. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11767. {
  11768. isMatchTransactiodId = TRUE;
  11769. break;
  11770. }
  11771. }
  11772. }
  11773. }
  11774. }
  11775. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11776. {
  11777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11778. {
  11779. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11780. }
  11781. else
  11782. {
  11783. tempIndex = SetProfileReq.ConnectorId -1;
  11784. }
  11785. for (int index = 0; index < GB_QUANTITY; index++)
  11786. {
  11787. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11788. {
  11789. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11790. {
  11791. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11792. {
  11793. isMatchTransactiodId = TRUE;
  11794. break;
  11795. }
  11796. }
  11797. }
  11798. }
  11799. }
  11800. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11801. {
  11802. tempIndex = SetProfileReq.ConnectorId -1;
  11803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11804. {
  11805. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11806. {
  11807. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11808. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11809. {
  11810. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11811. {
  11812. isMatchTransactiodId = TRUE;
  11813. break;
  11814. }
  11815. }
  11816. }
  11817. }
  11818. }
  11819. else
  11820. {
  11821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11822. {
  11823. tempIndex = 2;
  11824. }
  11825. else
  11826. {
  11827. tempIndex = (SetProfileReq.ConnectorId -1);
  11828. }
  11829. for (int index = 0; index < AC_QUANTITY; index++)
  11830. {
  11831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11832. {
  11833. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11834. {
  11835. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11836. {
  11837. isMatchTransactiodId = TRUE;
  11838. break;
  11839. }
  11840. }
  11841. }
  11842. }
  11843. }
  11844. //check Transaction active
  11845. if(isMatchTransactiodId == FALSE)
  11846. {
  11847. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11848. goto end;
  11849. }
  11850. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11851. {
  11852. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11853. goto end;
  11854. }
  11855. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11856. fp = fopen(filename, "r");
  11857. if (!fp)
  11858. {
  11859. DEBUG_INFO("%s does not create.\n", filename);
  11860. fp = fopen(filename, "w+");
  11861. }
  11862. else
  11863. {
  11864. //Check Charging Profile Count
  11865. while(fscanf(fp, "%s", dataLine) != EOF)
  11866. {
  11867. //DEBUG_INFO("word=%s\n",word);
  11868. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11869. {
  11870. profileQuantity += 1;
  11871. }
  11872. }
  11873. }
  11874. fclose(fp);
  11875. }
  11876. // Check ChargeProfileMaxStackLevel
  11877. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11878. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11879. {
  11880. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11881. goto end;
  11882. }
  11883. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11884. {
  11885. FILE *fp;
  11886. char dataLine[4096]={0};
  11887. char fnametemp[128]={0};
  11888. int tmpProfileQuantity;
  11889. //Check ChargePointMaxProfile.json exit
  11890. profileQuantity = 0;
  11891. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11892. {
  11893. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11894. //Check Charging Profile Count
  11895. tmpProfileQuantity = 0;
  11896. while(fscanf(fp, "%s", dataLine) != EOF)
  11897. {
  11898. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11899. {
  11900. profileQuantity += 1;
  11901. tmpProfileQuantity += 1;
  11902. }
  11903. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11904. }
  11905. fclose(fp);
  11906. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11907. }
  11908. //Check TxDefaultProfile_%d.json
  11909. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11910. {
  11911. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11912. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11913. if((access(fnametemp,F_OK))!=-1)
  11914. {
  11915. fp = fopen(fnametemp, "r");
  11916. //Check Charging Profile Count
  11917. tmpProfileQuantity = 0;
  11918. while(fscanf(fp, "%s", dataLine) != EOF)
  11919. {
  11920. //DEBUG_INFO("word=%s\n",word);
  11921. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11922. {
  11923. profileQuantity += 1;
  11924. tmpProfileQuantity += 1;
  11925. }
  11926. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11927. }
  11928. fclose(fp);
  11929. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11930. }
  11931. }
  11932. //Check TxProfile_%d.json
  11933. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11934. {
  11935. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11936. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11937. if((access(fnametemp,F_OK))!=-1)
  11938. {
  11939. fp = fopen(fnametemp, "r");
  11940. //Check Charging Profile Count
  11941. tmpProfileQuantity = 0;
  11942. while(fscanf(fp, "%s", dataLine) != EOF)
  11943. {
  11944. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11945. {
  11946. profileQuantity += 1;
  11947. tmpProfileQuantity += 1;
  11948. }
  11949. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11950. }
  11951. fclose(fp);
  11952. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11953. }
  11954. }
  11955. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11956. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11957. {
  11958. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11959. goto end;
  11960. }
  11961. }
  11962. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11963. //**********************************Write to File********************************************************/
  11964. {
  11965. FILE *infile;
  11966. FILE *outfile;
  11967. char dataLine[4096]={0};
  11968. char filename[128]={0};
  11969. int chkChar=0;
  11970. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11971. {
  11972. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11973. {
  11974. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11975. }
  11976. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11977. {
  11978. if(SetProfileReq.ConnectorId==0)
  11979. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11980. else
  11981. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11982. }
  11983. else
  11984. {
  11985. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11986. }
  11987. infile = fopen (filename, "r");
  11988. outfile = fopen (tempfile, "w");
  11989. chkChar = fgetc(infile);
  11990. rewind(infile);
  11991. if(chkChar == EOF)
  11992. {
  11993. // Profile is empty
  11994. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11995. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11996. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11997. fclose(infile);
  11998. fclose(outfile);
  11999. sprintf(rmFileCmd,"rm -f %s",filename);
  12000. system(rmFileCmd);
  12001. rename(tempfile, filename);
  12002. }
  12003. else
  12004. {
  12005. // Profile is not empty
  12006. int ChargingProfileAdded = FALSE;
  12007. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12008. {
  12009. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12010. json_object *tmpChargingProfile;
  12011. tmpChargingProfile = json_tokener_parse(dataLine);
  12012. if(!is_error(SetChargingProfile))
  12013. {
  12014. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12015. {
  12016. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12017. {
  12018. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12019. }
  12020. }
  12021. }
  12022. json_object_put(tmpChargingProfile);
  12023. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12024. {
  12025. if(ChargingProfileAdded == FALSE)
  12026. {
  12027. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12028. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12029. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12030. ChargingProfileAdded = TRUE;
  12031. }
  12032. }
  12033. else
  12034. {
  12035. fprintf(outfile,"%s\n",dataLine);
  12036. if(ChargingProfileAdded == FALSE)
  12037. {
  12038. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12039. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12040. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12041. ChargingProfileAdded = TRUE;
  12042. }
  12043. }
  12044. } // end of while loop
  12045. fclose(infile);
  12046. fclose(outfile);
  12047. sprintf(rmFileCmd,"rm -f %s",filename);
  12048. system(rmFileCmd);
  12049. rename(tempfile, filename);
  12050. }
  12051. }
  12052. sleep(1);
  12053. result = TRUE;
  12054. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12055. }
  12056. end:
  12057. json_object_put(SetChargingProfile);
  12058. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12059. {
  12060. if(SetProfileReq.ConnectorId == 0)
  12061. {
  12062. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12063. {
  12064. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12065. }
  12066. }
  12067. else
  12068. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12069. }
  12070. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12071. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12072. return result;
  12073. }
  12074. int handleTriggerMessageRequest(char *uuid, char *payload)
  12075. {
  12076. mtrace();
  12077. int result = FAIL;
  12078. int connectorIdIsNULL = FALSE;
  12079. int connectorIdInt =0;
  12080. char sstr[40]={0},sstrtemp[100]={ 0 };
  12081. char requestedMessagestr[40]={0};
  12082. char comfirmstr[20]={0};
  12083. int c = 0;
  12084. char *loc;
  12085. DEBUG_INFO("handleTriggerMessageRequest\n");
  12086. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12087. strcpy(sstrtemp, stringtrimspace(payload));
  12088. c = 0;
  12089. loc = strstr(sstrtemp, "requestedMessage");
  12090. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12091. {
  12092. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12093. c++;
  12094. }
  12095. sstr[c] = '\0';
  12096. strcpy(requestedMessagestr, sstr);
  12097. c = 0;
  12098. loc = strstr(sstrtemp, "connectorId");
  12099. if(loc == NULL)
  12100. {
  12101. connectorIdIsNULL = TRUE;
  12102. }
  12103. else
  12104. {
  12105. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12106. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12107. {
  12108. sstr[c] = loc[strlen("connectorId")+2+c];
  12109. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12110. c++;
  12111. }
  12112. sstr[c] = '\0';
  12113. connectorIdInt = atoi(sstr);
  12114. }
  12115. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12116. {
  12117. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12118. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12119. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12120. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12121. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12122. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12123. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12124. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12125. {
  12126. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12127. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12128. return TRUE;
  12129. }
  12130. else
  12131. {
  12132. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12133. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12134. }
  12135. }
  12136. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12137. {
  12138. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12139. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12140. return TRUE;
  12141. }
  12142. //==========================
  12143. // Trigger message
  12144. //==========================
  12145. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12146. {
  12147. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12148. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12149. {
  12150. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12151. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12152. }
  12153. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12154. }
  12155. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12156. {
  12157. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12158. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12159. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12160. }
  12161. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12162. {
  12163. //sendBootNotificationRequest();
  12164. server_sign = FALSE;
  12165. }
  12166. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12167. {
  12168. refreshStartTimer(&clientTime.Heartbeat);
  12169. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12170. }
  12171. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12172. {
  12173. if(connectorIdIsNULL == FALSE)
  12174. {
  12175. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12176. {
  12177. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12178. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12179. }
  12180. }
  12181. else
  12182. {
  12183. for(int idx=0;idx< gunTotalNumber;idx++)
  12184. {
  12185. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12186. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12187. }
  12188. }
  12189. }
  12190. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12191. {
  12192. if(connectorIdIsNULL == FALSE)
  12193. {
  12194. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12195. {
  12196. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12197. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12198. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12199. }
  12200. }
  12201. else
  12202. {
  12203. for(int idx=0;idx< gunTotalNumber;idx++)
  12204. {
  12205. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12206. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12207. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12208. }
  12209. }
  12210. }
  12211. return result;
  12212. }
  12213. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12214. {
  12215. mtrace();
  12216. int result = FAIL;
  12217. int connectorIdInt =0;
  12218. char comfirmstr[20]={0};
  12219. int tempIndex = 0;
  12220. json_object *UnlockConnector;
  12221. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12222. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12223. UnlockConnector = json_tokener_parse(payload);
  12224. if(!is_error(UnlockConnector))
  12225. {
  12226. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12227. {
  12228. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12229. }
  12230. }
  12231. json_object_put(UnlockConnector);
  12232. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12233. if(gunTotalNumber == 0)
  12234. {
  12235. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12236. goto end;
  12237. }
  12238. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12239. {
  12240. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12241. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12242. goto end;
  12243. }
  12244. else
  12245. {
  12246. //check Transaction active
  12247. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12248. {
  12249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12250. {
  12251. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12252. }
  12253. else
  12254. {
  12255. tempIndex = connectorIdInt -1;
  12256. }
  12257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12258. {
  12259. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12260. {
  12261. //stop Transaction
  12262. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12263. }
  12264. }
  12265. }
  12266. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12267. {
  12268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12269. {
  12270. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12271. }
  12272. else
  12273. {
  12274. tempIndex = connectorIdInt -1;
  12275. }
  12276. for (int index = 0; index < CCS_QUANTITY; index++)
  12277. {
  12278. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12279. {
  12280. //stop Transaction
  12281. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12282. }
  12283. }
  12284. }
  12285. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12286. {
  12287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12288. {
  12289. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12290. }
  12291. else
  12292. {
  12293. tempIndex = connectorIdInt -1;
  12294. }
  12295. for (int index = 0; index < GB_QUANTITY; index++)
  12296. {
  12297. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12298. {
  12299. //stop Transaction
  12300. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12301. }
  12302. }
  12303. }
  12304. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12305. {
  12306. tempIndex = connectorIdInt -1;
  12307. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12308. {
  12309. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12310. {
  12311. //stop Transaction
  12312. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12313. }
  12314. }
  12315. }
  12316. else
  12317. {
  12318. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12319. {
  12320. tempIndex = 2;
  12321. }
  12322. else
  12323. {
  12324. tempIndex = connectorIdInt-1;
  12325. }
  12326. for (int index = 0; index < AC_QUANTITY; index++)
  12327. {
  12328. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12329. {
  12330. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12331. }
  12332. }
  12333. }
  12334. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12335. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12336. result = TRUE;
  12337. return result;
  12338. }
  12339. end:
  12340. //json_object_put(obj); --- remove temporally
  12341. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12342. return result;
  12343. }
  12344. static char UpdateFirmwarepayloadData[300]={0};
  12345. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12346. {
  12347. mtrace();
  12348. int result = FAIL;
  12349. pthread_t t;
  12350. sendUpdateFirmwareConfirmation(uuid);
  12351. memset(UpdateFirmwarepayloadData, 0, 300);
  12352. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12353. if(!interLock.isUpdateFirmwareGoing)
  12354. {
  12355. interLock.isUpdateFirmwareGoing = 1;
  12356. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12357. sleep(1);
  12358. }
  12359. else
  12360. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12361. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12362. return result;
  12363. }
  12364. void *UpdateFirmwareProcess(void *data)
  12365. {
  12366. pthread_detach(pthread_self());
  12367. mtrace();
  12368. int retriesInt =0, retryIntervalInt=0;
  12369. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12370. int port=0;
  12371. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12372. int isSuccess = 0;
  12373. char ftpbuf[512];
  12374. char temp[100];
  12375. char * pch;
  12376. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12377. json_object *UpdateFirmware;
  12378. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12379. if(!is_error(UpdateFirmware))
  12380. {
  12381. // Required data
  12382. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12383. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12384. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12385. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12386. // Optional data
  12387. if(json_object_object_get(UpdateFirmware, "retries"))
  12388. {
  12389. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12390. }
  12391. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12392. {
  12393. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12394. }
  12395. }
  12396. json_object_put(UpdateFirmware);
  12397. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12398. memset(path, 0, ARRAY_SIZE(path));
  12399. // Wait retrieveData
  12400. if(strlen(retrieveDatestr) > 10)
  12401. {
  12402. do
  12403. {
  12404. sleep(1);
  12405. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12406. }
  12407. // Ready to download
  12408. system("rm -f /mnt/*");
  12409. if(strncmp(locationstr,"http", 4) == 0)
  12410. {
  12411. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12412. sprintf(ftppath,"/%s", path);
  12413. DEBUG_INFO("locationstr: %s\n", locationstr);
  12414. DEBUG_INFO("protocol: %s\n",protocol);
  12415. DEBUG_INFO("host: %s\n",host);
  12416. DEBUG_INFO("path: %s\n",path);
  12417. DEBUG_INFO("ftppath: %s\n",ftppath);
  12418. int ftppathlen=strlen(ftppath);
  12419. int i=1;
  12420. char filenametemp[50];
  12421. while(i < ftppathlen)
  12422. {
  12423. int len=ftppathlen-i;
  12424. if(ftppath[len]== 47) // '/' ascll code: 47
  12425. {
  12426. DEBUG_INFO("compare '/' all right\n");
  12427. break;
  12428. }
  12429. i=i+1;
  12430. }
  12431. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12432. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12433. filenametemp[i+1] = 0;
  12434. do
  12435. {
  12436. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12437. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12438. sleep(1);
  12439. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12440. if(!isSuccess)
  12441. {
  12442. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12443. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12444. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12445. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12446. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12447. }
  12448. else
  12449. {
  12450. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12451. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12452. }
  12453. retriesInt--;
  12454. }while((isSuccess == 0)&&(retriesInt >= 0));
  12455. }
  12456. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12457. {
  12458. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12459. memset(temp, 0, ARRAY_SIZE(temp));
  12460. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12461. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12462. int ftppathlen=strlen(ftpbuf);
  12463. int i=1;
  12464. char filenametemp[50];
  12465. while(i < ftppathlen)
  12466. {
  12467. int len=ftppathlen-i;
  12468. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12469. {
  12470. DEBUG_INFO(" compare '/' all right\n");
  12471. break;
  12472. }
  12473. i=i+1;
  12474. }
  12475. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12476. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12477. filenametemp[i+1] = 0;
  12478. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12479. pch=strchr(temp,'@');
  12480. if(pch==NULL)
  12481. {
  12482. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12483. protocol, host, &port, path);
  12484. strcpy(user,"anonymous");
  12485. strcpy(password,"");
  12486. }
  12487. else
  12488. {
  12489. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12490. protocol, user, password, host, &port, path);
  12491. }
  12492. sscanf(host,"%[^/]%s",host1, path1);
  12493. sprintf(ftppath,"%s", path1);
  12494. //DEBUG_INFO("protocol =%s\n",protocol);
  12495. //DEBUG_INFO("user =%s\n",user);
  12496. //DEBUG_INFO("password =%s\n",password);
  12497. //DEBUG_INFO("host1 =%s\n",host1);
  12498. //DEBUG_INFO("port =%d\n",port);
  12499. //DEBUG_INFO("path1 =%s\n",path1);
  12500. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12501. //ftpFile(host, user, password, port, ftppath, fname);
  12502. //download firmware pthred
  12503. if(port == 0)
  12504. {
  12505. port = 21;
  12506. }
  12507. do
  12508. {
  12509. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12510. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12511. sleep(1);
  12512. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12513. if(!isSuccess)
  12514. {
  12515. //BulldogUtil.sleepMs(interval*1000);
  12516. DEBUG_INFO("Update firmware request and download file fail.\n");
  12517. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12518. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12519. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12520. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12521. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12522. }
  12523. else
  12524. {
  12525. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12526. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12527. }
  12528. retriesInt--;
  12529. }while((!isSuccess)&&(retriesInt >= 0));
  12530. }
  12531. else
  12532. {
  12533. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12534. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12535. sleep(1);
  12536. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12537. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12538. }
  12539. // OCPPPH only, must announce CSU upgrade firmware
  12540. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12541. interLock.isUpdateFirmwareGoing = 0;
  12542. pthread_exit(NULL);
  12543. }
  12544. int handleCertificateSignedRequest(char *uuid, char *payload)
  12545. {
  12546. mtrace();
  12547. int result = PASS;
  12548. json_object *CertificateSigned;
  12549. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12550. CertificateSigned = json_tokener_parse(payload);
  12551. if(!is_error(CertificateSigned))
  12552. {
  12553. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12554. }
  12555. json_object_put(CertificateSigned);
  12556. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12557. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12558. fclose(fp);
  12559. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12560. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12561. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12562. sendCertificateSignedConfirmation(uuid);
  12563. return result;
  12564. }
  12565. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12566. {
  12567. mtrace();
  12568. int result = PASS;
  12569. json_object *DeleteCertificate;
  12570. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12571. DeleteCertificate = json_tokener_parse(payload);
  12572. if(!is_error(DeleteCertificate))
  12573. {
  12574. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12575. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12576. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12577. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12578. }
  12579. json_object_put(DeleteCertificate);
  12580. /*
  12581. * TODO: Delete certificateSigned process
  12582. */
  12583. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12584. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12585. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12586. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12587. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12588. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12589. sendDeleteCertificateConfirmation(uuid);
  12590. return result;
  12591. }
  12592. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12593. {
  12594. mtrace();
  12595. int result = PASS;
  12596. json_object *ExtendedTriggerMessage;
  12597. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12598. ExtendedTriggerMessage = json_tokener_parse(payload);
  12599. if(!is_error(ExtendedTriggerMessage))
  12600. {
  12601. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12602. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12603. {
  12604. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12605. }
  12606. else
  12607. {
  12608. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12609. }
  12610. }
  12611. json_object_put(ExtendedTriggerMessage);
  12612. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12613. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12614. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12615. {
  12616. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12617. }
  12618. else
  12619. {
  12620. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12621. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12622. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12623. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12624. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12625. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12626. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12627. {
  12628. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12629. }
  12630. else
  12631. {
  12632. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12633. }
  12634. }
  12635. sendExtendedTriggerMessageConfirmation(uuid);
  12636. //==========================
  12637. // Trigger message
  12638. //==========================
  12639. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12640. {
  12641. //sendBootNotificationRequest();
  12642. server_sign = FALSE;
  12643. }
  12644. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12645. {
  12646. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12647. }
  12648. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12649. {
  12650. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12651. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12652. {
  12653. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12654. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12655. }
  12656. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12657. }
  12658. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12659. {
  12660. refreshStartTimer(&clientTime.Heartbeat);
  12661. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12662. }
  12663. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12664. {
  12665. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12666. {
  12667. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12668. }
  12669. else
  12670. {
  12671. for(int idx=0;idx< gunTotalNumber;idx++)
  12672. {
  12673. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12674. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12675. }
  12676. }
  12677. }
  12678. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12679. {
  12680. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12681. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12682. {
  12683. 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\" &");
  12684. }
  12685. }
  12686. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12687. {
  12688. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12689. {
  12690. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12691. }
  12692. else
  12693. {
  12694. for(int idx=0;idx< gunTotalNumber;idx++)
  12695. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12696. }
  12697. }
  12698. return result;
  12699. }
  12700. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12701. {
  12702. mtrace();
  12703. int result = PASS;
  12704. json_object *GetInstalledCertificateIds;
  12705. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12706. GetInstalledCertificateIds = json_tokener_parse(payload);
  12707. if(!is_error(GetInstalledCertificateIds))
  12708. {
  12709. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12710. }
  12711. json_object_put(GetInstalledCertificateIds);
  12712. /*
  12713. * TODO: Return installed certificate process
  12714. */
  12715. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12716. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12717. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12718. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12719. sendGetInstalledCertificateIdsConfirmation(uuid);
  12720. return result;
  12721. }
  12722. int handleGetLogRequest(char *uuid, char *payload)
  12723. {
  12724. mtrace();
  12725. int result = PASS;
  12726. json_object *GetLog;
  12727. DEBUG_INFO("handleGetLogRequest...\n");
  12728. GetLog = json_tokener_parse(payload);
  12729. if(!is_error(GetLog))
  12730. {
  12731. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12732. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12733. if(json_object_object_get(GetLog, "retries") != NULL)
  12734. {
  12735. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12736. }
  12737. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12738. {
  12739. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12740. }
  12741. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12742. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12743. {
  12744. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12745. }
  12746. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12747. {
  12748. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12749. }
  12750. }
  12751. json_object_put(GetLog);
  12752. /*
  12753. * TODO: Upload log process
  12754. */
  12755. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12756. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12757. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12758. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12759. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12760. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12761. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12762. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12763. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12764. sendGetLogConfirmation(uuid);
  12765. return result;
  12766. }
  12767. int handleInstallCertificateRequest(char *uuid, char *payload)
  12768. {
  12769. mtrace();
  12770. int result = PASS;
  12771. json_object *InstallCertificate;
  12772. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12773. InstallCertificate = json_tokener_parse(payload);
  12774. if(!is_error(InstallCertificate))
  12775. {
  12776. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12777. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12778. /*
  12779. * TODO: Install certificate process
  12780. */
  12781. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12782. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12783. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12784. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12785. sendInstallCertificateConfirmation(uuid);
  12786. }
  12787. json_object_put(InstallCertificate);
  12788. return result;
  12789. }
  12790. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12791. {
  12792. mtrace();
  12793. int result = PASS;
  12794. json_object *SignedUpdateFirmware;
  12795. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12796. SignedUpdateFirmware = json_tokener_parse(payload);
  12797. if(!is_error(SignedUpdateFirmware))
  12798. {
  12799. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12800. {
  12801. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12802. }
  12803. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12804. {
  12805. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12806. }
  12807. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12808. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12809. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12810. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12811. {
  12812. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12813. }
  12814. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12815. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12816. }
  12817. json_object_put(SignedUpdateFirmware);
  12818. /*
  12819. * TODO: Upgrade firmware process
  12820. */
  12821. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12822. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12823. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12824. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12825. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12826. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12827. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12828. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12829. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12830. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12831. sendInstallCertificateConfirmation(uuid);
  12832. return result;
  12833. }
  12834. int handleUnknownRequest(char *uuid, char *payload)
  12835. {
  12836. mtrace();
  12837. int result = PASS;
  12838. DEBUG_INFO("handleUnknownRequest...\n");
  12839. sendUnknownConfirmation(uuid);
  12840. result = PASS;
  12841. return result;
  12842. }
  12843. //==========================================
  12844. // Handle server response routine
  12845. //==========================================
  12846. void handleAuthorizeResponse(char *payload, int gun_index)
  12847. {
  12848. mtrace();
  12849. char expiryDatestr[30]={0};
  12850. char parentIdTagstr[20]={0};
  12851. char statusstr[20]={0};
  12852. int expiryDateISNULL=FALSE;
  12853. int parentIdTagISNULL=FALSE;
  12854. DEBUG_INFO("handleAuthorizeResponse...\n");
  12855. json_object *Authorize;
  12856. Authorize = json_tokener_parse(payload);
  12857. if(!is_error(Authorize))
  12858. {
  12859. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12860. {
  12861. // Required data
  12862. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12863. // Optional data
  12864. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12865. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12866. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12867. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12868. }
  12869. }
  12870. json_object_put(Authorize);
  12871. if(expiryDateISNULL == FALSE)
  12872. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12873. if(parentIdTagISNULL == FALSE)
  12874. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12875. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12876. //Update idTag information to authorization cache if supproted
  12877. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12878. {
  12879. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12880. }
  12881. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12882. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12883. authorizeRetryTimes = 0;
  12884. }
  12885. void handleBootNotificationResponse(char *payload, int gun_index)
  12886. {
  12887. mtrace();
  12888. char statusStr[12]={0};
  12889. char currentTimeStr[30]={0};
  12890. int intervalInt = 0;
  12891. DEBUG_INFO("handleBootNotificationResponse...\n");
  12892. json_object *BootNotification;
  12893. BootNotification = json_tokener_parse(payload);
  12894. if(!is_error(BootNotification))
  12895. {
  12896. // Required data
  12897. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12898. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12899. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12900. }
  12901. json_object_put(BootNotification);
  12902. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12903. BootNotificationInterval = intervalInt;
  12904. HeartBeatWaitTime = intervalInt;
  12905. //write back to ShmOCPP16DataPH->BootNotification
  12906. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12907. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12908. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12909. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12910. {
  12911. if((intervalInt == 0) || (intervalInt >= 10))
  12912. {
  12913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12914. HeartBeatWaitTime = intervalInt;
  12915. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12916. }
  12917. server_sign = TRUE;
  12918. server_pending =FALSE;
  12919. }
  12920. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12921. {
  12922. server_pending = TRUE;
  12923. }
  12924. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12925. srand(time(NULL));
  12926. refreshStartTimer(&clientTime.Heartbeat);
  12927. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12928. SetOcppConnStatus(TRUE);
  12929. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12930. }
  12931. void handleDataTransferResponse(char *payload, int gun_index)
  12932. {
  12933. json_object *DataTransfer = json_tokener_parse(payload);
  12934. if(!is_error(DataTransfer))
  12935. {
  12936. // Required data
  12937. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12938. // Optional data
  12939. if(json_object_object_get(DataTransfer, "data") != NULL)
  12940. {
  12941. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12942. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12943. if(!is_error(Data))
  12944. {
  12945. if(json_object_object_get(Data, "msgId") != NULL)
  12946. {
  12947. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12948. {
  12949. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  12950. }
  12951. }
  12952. }
  12953. json_object_put(Data);
  12954. }
  12955. }
  12956. json_object_put(DataTransfer);
  12957. }
  12958. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12959. {
  12960. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12961. //struct json_object *obj;
  12962. // obj = json_tokener_parse(payload);
  12963. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12964. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12965. //No fields are defined.
  12966. }
  12967. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12968. {
  12969. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12970. //struct json_object *obj;
  12971. // obj = json_tokener_parse(payload);
  12972. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12973. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12974. //No fields are defined.
  12975. }
  12976. void handleHeartbeatResponse(char *payload, int gun_index)
  12977. {
  12978. mtrace();
  12979. DEBUG_INFO("handleHeartbeatResponse...\n");
  12980. json_object *Heartbeat;
  12981. Heartbeat = json_tokener_parse(payload);
  12982. if(!is_error(Heartbeat))
  12983. {
  12984. // Required data
  12985. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12986. }
  12987. json_object_put(Heartbeat);
  12988. if(FirstHeartBeat == 0)
  12989. {
  12990. FirstHeartBeat = 1;
  12991. DEBUG_INFO("FirstHeartBeat \n");
  12992. }
  12993. HeartBeatWithNOResponse = 0;
  12994. refreshStartTimer(&clientTime.Heartbeat);
  12995. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12996. }
  12997. void handleMeterValuesResponse(char *payload, int gun_index)
  12998. {
  12999. mtrace();
  13000. DEBUG_INFO("handleMeterValuesResponse...\n");
  13001. isQueueSendable = 1;
  13002. }
  13003. void handleStartTransactionResponse(char *payload, int gun_index)
  13004. {
  13005. mtrace();
  13006. //int transactionIdInt = 0;
  13007. FILE *outfile;
  13008. char data[100]={0};
  13009. DEBUG_INFO("handleStartTransactionResponse...\n");
  13010. json_object *StartTransaction;
  13011. StartTransaction = json_tokener_parse(payload);
  13012. if(!is_error(StartTransaction))
  13013. {
  13014. // Required data
  13015. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13016. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13017. // Optional data
  13018. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13019. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13020. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13021. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13022. }
  13023. json_object_put(StartTransaction);
  13024. isQueueSendable = 1;
  13025. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13026. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13027. //-----------Start : write to the Queue TransactionId file -----------------//
  13028. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13029. {}
  13030. else
  13031. {
  13032. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13033. if(log == NULL)
  13034. {
  13035. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13036. return ;
  13037. }
  13038. else
  13039. {
  13040. fclose(log);
  13041. }
  13042. }
  13043. // open file for writing
  13044. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13045. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13046. {
  13047. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13048. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13049. fputs(data, outfile);
  13050. fclose (outfile);
  13051. }
  13052. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13053. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13054. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13055. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13056. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13057. }
  13058. void handleStatusNotificationResponse(char *payload, int gun_index)
  13059. {
  13060. mtrace();
  13061. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13062. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13063. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13064. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13065. }
  13066. void handleStopTransactionnResponse(char *payload, int gun_index)
  13067. {
  13068. mtrace();
  13069. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13070. json_object *StopTransaction;
  13071. StopTransaction = json_tokener_parse(payload);
  13072. if(!is_error(StopTransaction))
  13073. {
  13074. // Optional data
  13075. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13076. {
  13077. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13078. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13079. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13080. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13081. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13082. }
  13083. }
  13084. json_object_put(StopTransaction);
  13085. isQueueSendable = 1;
  13086. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13087. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13088. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13089. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13090. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13091. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13092. }
  13093. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13094. {
  13095. mtrace();
  13096. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13097. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13098. }
  13099. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13100. {
  13101. mtrace();
  13102. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13103. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13104. }
  13105. void handleSignCertificateResponse(char *payload, int gun_index)
  13106. {
  13107. mtrace();
  13108. DEBUG_INFO("handleSignCertificateResponse...\n");
  13109. json_object *SignCertificate;
  13110. SignCertificate = json_tokener_parse(payload);
  13111. if(!is_error(SignCertificate))
  13112. {
  13113. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13114. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13115. }
  13116. json_object_put(SignCertificate);
  13117. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13118. }
  13119. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13120. {
  13121. mtrace();
  13122. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13123. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13124. }
  13125. //==========================================
  13126. // Handle Error routine
  13127. //==========================================
  13128. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13129. {
  13130. mtrace();
  13131. #ifdef SystemLogMessage
  13132. DEBUG_INFO("errorCode: %s\n", errorCode);
  13133. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13134. DEBUG_INFO("errorDetails: %s\n", payload);
  13135. #endif
  13136. }
  13137. //===============================================
  13138. // Common routine
  13139. //===============================================
  13140. int initialConfigurationTable(void)
  13141. {
  13142. //clock_t start_t, end_t, total_t;
  13143. FILE *fp;
  13144. FILE *outfile;
  13145. char str[512]={0};
  13146. char sstr[256]={0};
  13147. int c = 0;
  13148. char *loc;
  13149. int confVersion = 13;
  13150. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13151. //start_t = clock();
  13152. //printf("Starting of the program, start_t = %ld\n", start_t);
  13153. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13154. // Check configuration file size is correct
  13155. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13156. {
  13157. struct stat st;
  13158. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13159. if(st.st_size < 3100)
  13160. {
  13161. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13162. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13163. }
  13164. }
  13165. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13166. {
  13167. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13168. if(outfile == NULL)
  13169. {
  13170. DEBUG_INFO("Error opening file\n");
  13171. return FALSE;
  13172. }
  13173. /*Core Profile*/
  13174. //AllowOfflineTxForUnknownId
  13175. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13179. //AuthorizationCacheEnabled
  13180. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13184. //AuthorizeRemoteTxRequests
  13185. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13189. //BlinkRepeat
  13190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13194. //ClockAlignedDataInterval
  13195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13199. //ConnectionTimeOut
  13200. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13204. //GetConfigurationMaxKeys
  13205. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13207. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13209. // HeartbeatInterval
  13210. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13214. // LightIntensity
  13215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13219. // LocalAuthorizeOffline
  13220. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13224. // LocalPreAuthorize
  13225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13229. // MaxEnergyOnInvalidId
  13230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13234. // MeterValuesAlignedData
  13235. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13238. 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" );
  13239. else
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13242. // MeterValuesAlignedDataMaxLength
  13243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13247. else
  13248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13250. // MeterValuesSampledData
  13251. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13252. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13254. 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" );
  13255. else
  13256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13258. // MeterValuesSampledDataMaxLength
  13259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13263. else
  13264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13266. // MeterValueSampleInterval
  13267. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13271. // MinimumStatusDuration
  13272. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13273. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13275. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13277. // NumberOfConnectors
  13278. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13281. {
  13282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13283. }
  13284. else
  13285. {
  13286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13287. }
  13288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13289. // ResetRetries
  13290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13294. // ConnectorPhaseRotation
  13295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13299. // ConnectorPhaseRotationMaxLength
  13300. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13304. // StopTransactionOnEVSideDisconnect
  13305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13309. // StopTransactionOnInvalidId
  13310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13314. // StopTxnAlignedData
  13315. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13319. // StopTxnAlignedDataMaxLength
  13320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13324. // StopTxnSampledData
  13325. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13329. else
  13330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13332. // StopTxnSampledDataMaxLength
  13333. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13335. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13336. {
  13337. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13338. }
  13339. else
  13340. {
  13341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13342. }
  13343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13344. // SupportedFeatureProfiles
  13345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13349. // SupportedFeatureProfilesMaxLength
  13350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13354. // TransactionMessageAttempts
  13355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13358. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13360. // TransactionMessageRetryInterval
  13361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13364. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13366. // UnlockConnectorOnEVSideDisconnect
  13367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13371. // WebSocketPingInterval
  13372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13376. // QueueOffLineMeterValues
  13377. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13381. // AuthorizationKey
  13382. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13386. // SecurityProfile
  13387. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13391. // DefaultPrice
  13392. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13396. // CustomDisplayCostAndPrice
  13397. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13401. // CustomIdleFeeAfterStop
  13402. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13406. // SystemUptimeSec
  13407. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13411. // FreeVend
  13412. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13414. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13416. // FreeVendIdtag
  13417. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13421. // OcppServer
  13422. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13424. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13426. // MaintainServer
  13427. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13429. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13431. // StatusNotificationPeriodically
  13432. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13436. // StatusNotificationInterval
  13437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13439. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13441. // Configuration Version
  13442. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13444. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13446. //* Local Auth List Management Profile*/
  13447. #if 0
  13448. //For OCTT Test Case
  13449. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13450. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13451. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13452. #endif
  13453. #if 1
  13454. //LocalAuthListEnabled
  13455. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13459. #endif
  13460. //LocalAuthListMaxLength
  13461. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13465. //SendLocalListMaxLength
  13466. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13468. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13470. //ReserveConnectorZeroSupported
  13471. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13475. //* Smart Charging Profile */
  13476. //ChargeProfileMaxStackLevel
  13477. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13478. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13479. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13481. // ChargingScheduleAllowedChargingRateUnit
  13482. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13484. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13486. // ChargingScheduleMaxPeriods
  13487. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13491. // ConnectorSwitch3to1PhaseSupported
  13492. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13493. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13496. // MaxChargingProfilesInstalled
  13497. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13499. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13501. fclose(outfile);
  13502. }
  13503. else
  13504. {
  13505. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13506. char keystr[60]={0};
  13507. char readonlystr[10]={0};
  13508. char valuestr[256]={0};
  13509. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13510. if(fp == NULL) {
  13511. DEBUG_INFO("Error opening file");
  13512. return FALSE;
  13513. }
  13514. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13515. {
  13516. //DEBUG_INFO("Get Configuration \n");
  13517. if(strlen(str) > 0)
  13518. {
  13519. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13520. //*************************key*********************************/
  13521. if(strstr(str, "key") != NULL)
  13522. {
  13523. loc = strstr(str, "key");
  13524. c = 0;
  13525. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13526. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13527. {
  13528. sstr[c] = loc[strlen("key")+3+c];
  13529. c++;
  13530. }
  13531. sstr[c] = '\0';
  13532. strcpy(keystr,sstr);
  13533. }
  13534. //*************************readonly*********************************/
  13535. if(strstr(str, "readonly") != NULL)
  13536. {
  13537. loc = strstr(str, "readonly");
  13538. c = 0;
  13539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13540. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13541. {
  13542. sstr[c] = loc[strlen("readonly")+2+c];
  13543. c++;
  13544. }
  13545. sstr[c] = '\0';
  13546. strcpy(readonlystr,sstr);
  13547. }
  13548. //*************************value*********************************/
  13549. if(strstr(str, "value") != NULL)
  13550. {
  13551. loc = strstr(str, "value");
  13552. c = 0;
  13553. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13554. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13555. {
  13556. sstr[c] = loc[strlen("value")+3+c];
  13557. c++;
  13558. }
  13559. sstr[c] = '\0';
  13560. strcpy(valuestr,sstr);
  13561. }
  13562. // DEBUG_INFO("keystr=%s\n",keystr);
  13563. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13564. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13565. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13566. {
  13567. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13568. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13570. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13571. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13572. }
  13573. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13574. {
  13575. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13578. }
  13579. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13580. {
  13581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13582. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13583. }
  13584. if(strcmp(keystr, "BlinkRepeat") == 0)
  13585. {
  13586. //Charger.BlinkRepeat = Integer.parseInt(value);
  13587. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13589. }
  13590. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13591. {
  13592. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13594. }
  13595. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13596. {
  13597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13599. }
  13600. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13601. {
  13602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13604. }
  13605. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13606. {
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13609. HeartBeatWaitTime = atoi(valuestr);
  13610. }
  13611. if(strcmp(keystr, "LightIntensity") == 0)
  13612. {
  13613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13614. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13615. }
  13616. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13617. {
  13618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13620. }
  13621. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13622. {
  13623. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13625. }
  13626. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13627. {
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13630. }
  13631. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13632. {
  13633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13635. }
  13636. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13637. {
  13638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13640. }
  13641. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13642. {
  13643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13645. }
  13646. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13647. {
  13648. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13649. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13650. }
  13651. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13652. {
  13653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13655. }
  13656. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13657. {
  13658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13660. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13661. }
  13662. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13663. {
  13664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13665. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13666. }
  13667. if(strcmp(keystr, "ResetRetries") == 0)
  13668. {
  13669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13671. }
  13672. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13673. {
  13674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13676. }
  13677. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13678. {
  13679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13681. }
  13682. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13683. {
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13686. }
  13687. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13688. {
  13689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13691. }
  13692. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13693. {
  13694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13695. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13696. }
  13697. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13698. {
  13699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13701. }
  13702. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13703. {
  13704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13706. }
  13707. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13708. {
  13709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13711. }
  13712. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13713. {
  13714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13716. }
  13717. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13718. {
  13719. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13721. }
  13722. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13723. {
  13724. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13725. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13726. TransactionMessageAttemptsValue = atoi(valuestr);
  13727. }
  13728. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13729. {
  13730. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13732. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13733. }
  13734. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13735. {
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13738. }
  13739. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13740. {
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13743. }
  13744. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13745. {
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13748. }
  13749. if(strcmp(keystr, "AuthorizationKey") == 0)
  13750. {
  13751. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13752. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13754. }
  13755. if(strcmp(keystr, "SecurityProfile") == 0)
  13756. {
  13757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13758. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13759. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13760. }
  13761. if(strcmp(keystr, "DefaultPrice") == 0)
  13762. {
  13763. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13765. }
  13766. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13767. {
  13768. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13770. }
  13771. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13772. {
  13773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13775. }
  13776. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13777. {
  13778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13780. }
  13781. if(strcmp(keystr, "FreeVend") == 0)
  13782. {
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13785. }
  13786. if(strcmp(keystr, "FreeVendIdtag") == 0)
  13787. {
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13789. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  13790. }
  13791. if(strcmp(keystr, "OcppServer") == 0)
  13792. {
  13793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13794. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13795. }
  13796. if(strcmp(keystr, "MaintainServer") == 0)
  13797. {
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13799. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13800. }
  13801. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13802. {
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13804. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13805. }
  13806. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13807. {
  13808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13809. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13810. }
  13811. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13812. {
  13813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13814. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13815. }
  13816. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13817. {
  13818. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13820. }
  13821. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13822. {
  13823. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13824. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13825. }
  13826. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13827. {
  13828. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13829. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13830. }
  13831. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13832. {
  13833. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13835. }
  13836. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13837. {
  13838. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13839. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13840. }
  13841. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13842. {
  13843. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13845. }
  13846. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13847. {
  13848. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13850. }
  13851. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13852. {
  13853. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13854. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13855. }
  13856. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13857. {
  13858. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13859. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13860. }
  13861. }
  13862. }
  13863. fclose(fp);
  13864. }
  13865. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13866. {
  13867. return PASS;
  13868. }
  13869. else
  13870. {
  13871. return FAIL;
  13872. }
  13873. }
  13874. void StoreConfigurationTable(void)
  13875. {
  13876. FILE *outfile;
  13877. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13878. if(outfile == NULL)
  13879. {
  13880. DEBUG_INFO("Error opening file");
  13881. return ;
  13882. }
  13883. /*Core Profile*/
  13884. //AllowOfflineTxForUnknownId
  13885. /*
  13886. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13887. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13890. */
  13891. //DEBUG_INFO("data=%s\n",data);
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13893. //AuthorizationCacheEnabled
  13894. /*
  13895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13898. */
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13900. //AuthorizeRemoteTxRequests
  13901. /*
  13902. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13905. */
  13906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13907. //BlinkRepeat
  13908. /*
  13909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13912. */
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13914. //ClockAlignedDataInterval
  13915. /*
  13916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13919. */
  13920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13921. //ConnectionTimeOut
  13922. /*
  13923. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13926. */
  13927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13928. //GetConfigurationMaxKeys
  13929. /*
  13930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13933. */
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13935. // HeartbeatInterval
  13936. /*
  13937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13940. */
  13941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13942. // LightIntensity
  13943. /*
  13944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13947. */
  13948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13949. // LocalAuthorizeOffline
  13950. /*
  13951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13954. */
  13955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13956. // LocalPreAuthorize
  13957. /*
  13958. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13961. */
  13962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13963. // MaxEnergyOnInvalidId
  13964. /*
  13965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13968. */
  13969. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13971. // MeterValuesAlignedData
  13972. /*
  13973. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13976. */
  13977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13978. // MeterValuesAlignedDataMaxLength
  13979. /*
  13980. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13983. */
  13984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13985. // MeterValuesSampledData
  13986. /*
  13987. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13990. */
  13991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13992. // MeterValuesSampledDataMaxLength
  13993. /*
  13994. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13997. */
  13998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13999. // MeterValueSampleInterval
  14000. /*
  14001. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14003. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14004. */
  14005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14006. // MinimumStatusDuration
  14007. /*
  14008. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14011. */
  14012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14013. // NumberOfConnectors
  14014. /*
  14015. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14018. {
  14019. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14020. }
  14021. else
  14022. {
  14023. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14024. }
  14025. */
  14026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14027. // ResetRetries
  14028. /*
  14029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14032. */
  14033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14034. // ConnectorPhaseRotation
  14035. /*
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14039. */
  14040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14041. // ConnectorPhaseRotationMaxLength
  14042. /*
  14043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14046. */
  14047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14048. // StopTransactionOnEVSideDisconnect
  14049. /*
  14050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14053. */
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14055. // StopTransactionOnInvalidId
  14056. /*
  14057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14060. */
  14061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14062. // StopTxnAlignedData
  14063. /*
  14064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14067. */
  14068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14069. // StopTxnAlignedDataMaxLength
  14070. /*
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14074. */
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14076. // StopTxnSampledData
  14077. /*
  14078. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14081. */
  14082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14083. // StopTxnSampledDataMaxLength
  14084. /*
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14088. */
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14090. // SupportedFeatureProfiles
  14091. /*
  14092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14095. */
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14097. // SupportedFeatureProfilesMaxLength
  14098. /*
  14099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14102. */
  14103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14104. // TransactionMessageAttempts
  14105. /*
  14106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14109. */
  14110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14111. // TransactionMessageRetryInterval
  14112. /*
  14113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14116. */
  14117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14118. // UnlockConnectorOnEVSideDisconnect
  14119. /*
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14123. */
  14124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14125. // WebSocketPingInterval
  14126. /*
  14127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14130. */
  14131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14132. // QueueOffLineMeterValues
  14133. /*
  14134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14137. */
  14138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14139. // AuthorizationKey
  14140. /*
  14141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14144. */
  14145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14146. // SecurityProfile
  14147. /*
  14148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14151. */
  14152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14153. // DefaultPrice
  14154. /*
  14155. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14158. */
  14159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14160. // CustomDisplayCostAndPrice
  14161. /*
  14162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14165. */
  14166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14167. // CustomIdleFeeAfterStop
  14168. /*
  14169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14172. */
  14173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14174. // SystemUptimeSec
  14175. /*
  14176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14179. */
  14180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14181. // FreeVend
  14182. /*
  14183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14186. */
  14187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14188. // FreeVendIdtag
  14189. /*
  14190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14193. */
  14194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14195. // OcppServer
  14196. /*
  14197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14200. */
  14201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14202. // MaintainServer
  14203. /*
  14204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14207. */
  14208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14209. // StatusNotificationPeriodically
  14210. /*
  14211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14214. */
  14215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14216. // StatusNotificationInterval
  14217. /*
  14218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14221. */
  14222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14223. // ConfigurationVersion
  14224. /*
  14225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14228. */
  14229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14230. //* Local Auth List Management Profile*/
  14231. //LocalAuthListEnabled
  14232. /*
  14233. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14236. */
  14237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14238. //LocalAuthListMaxLength
  14239. /*
  14240. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14243. */
  14244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14245. //SendLocalListMaxLength
  14246. /*
  14247. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14250. */
  14251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14252. //ReserveConnectorZeroSupported
  14253. /*
  14254. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14257. */
  14258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14259. //* Smart Charging Profile */
  14260. //ChargeProfileMaxStackLevel
  14261. /*
  14262. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14265. */
  14266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14267. // ChargingScheduleAllowedChargingRateUnit
  14268. /*
  14269. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14272. */
  14273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14274. // ChargingScheduleMaxPeriods
  14275. /*
  14276. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14279. */
  14280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14281. // ConnectorSwitch3to1PhaseSupported
  14282. /*
  14283. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14286. */
  14287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14288. // MaxChargingProfilesInstalled
  14289. /*
  14290. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14293. */
  14294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14295. fclose(outfile);
  14296. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14297. }
  14298. void getKeyValue(char *keyReq)
  14299. {
  14300. int isEmpty = FALSE;
  14301. int isKnowKey = FALSE;
  14302. DEBUG_INFO("keyReq = %s\n", keyReq);
  14303. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14304. isEmpty = TRUE;
  14305. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14306. {
  14307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14309. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14310. {
  14311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14312. }
  14313. else
  14314. {
  14315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14316. }
  14317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14318. isKnowKey = TRUE;
  14319. }
  14320. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14321. {
  14322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14324. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14325. {
  14326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14327. }
  14328. else
  14329. {
  14330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14331. }
  14332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14333. isKnowKey = TRUE;
  14334. }
  14335. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14336. {
  14337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14339. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14340. {
  14341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14342. }
  14343. else
  14344. {
  14345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14346. }
  14347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14348. isKnowKey = TRUE;
  14349. }
  14350. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14351. {
  14352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14354. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14355. {
  14356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14357. }
  14358. else
  14359. {
  14360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14361. }
  14362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14363. isKnowKey = TRUE;
  14364. }
  14365. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14366. {
  14367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14369. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14370. {
  14371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14372. }
  14373. else
  14374. {
  14375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14376. }
  14377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14378. isKnowKey = TRUE;
  14379. }
  14380. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14381. {
  14382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14384. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14385. {
  14386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14387. }
  14388. else
  14389. {
  14390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14391. }
  14392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14393. isKnowKey = TRUE;
  14394. }
  14395. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14396. {
  14397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14399. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14400. {
  14401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14402. }
  14403. else
  14404. {
  14405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14406. }
  14407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14408. isKnowKey = TRUE;
  14409. }
  14410. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14411. {
  14412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14414. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14415. {
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14417. }
  14418. else
  14419. {
  14420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14421. }
  14422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14423. isKnowKey = TRUE;
  14424. }
  14425. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14426. {
  14427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14429. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14430. {
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14432. }
  14433. else
  14434. {
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14436. }
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14438. isKnowKey = TRUE;
  14439. }
  14440. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14441. {
  14442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14445. {
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14447. }
  14448. else
  14449. {
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14451. }
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14453. isKnowKey = TRUE;
  14454. }
  14455. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14456. {
  14457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14459. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14460. {
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14462. }
  14463. else
  14464. {
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14466. }
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14468. isKnowKey = TRUE;
  14469. }
  14470. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14471. {
  14472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14475. {
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14477. }
  14478. else
  14479. {
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14481. }
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14483. isKnowKey = TRUE;
  14484. }
  14485. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14486. {
  14487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14490. {
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14492. }
  14493. else
  14494. {
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14496. }
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14498. isKnowKey = TRUE;
  14499. }
  14500. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14501. {
  14502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14505. {
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14507. }
  14508. else
  14509. {
  14510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14511. }
  14512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14513. isKnowKey = TRUE;
  14514. }
  14515. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14516. {
  14517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14519. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14520. {
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14522. }
  14523. else
  14524. {
  14525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14526. }
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14528. isKnowKey = TRUE;
  14529. }
  14530. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14531. {
  14532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14534. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14535. {
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14537. }
  14538. else
  14539. {
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14541. }
  14542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14543. isKnowKey = TRUE;
  14544. }
  14545. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14546. {
  14547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14549. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14550. {
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14552. }
  14553. else
  14554. {
  14555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14556. }
  14557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14558. isKnowKey = TRUE;
  14559. }
  14560. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14561. {
  14562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14564. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14565. {
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14567. }
  14568. else
  14569. {
  14570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14571. }
  14572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14573. isKnowKey = TRUE;
  14574. }
  14575. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14576. {
  14577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14579. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14580. {
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14582. }
  14583. else
  14584. {
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14586. }
  14587. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14589. isKnowKey = TRUE;
  14590. }
  14591. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14592. {
  14593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14595. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14596. {
  14597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14598. }
  14599. else
  14600. {
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14602. }
  14603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14604. isKnowKey = TRUE;
  14605. }
  14606. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14607. {
  14608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14610. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14611. {
  14612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14613. }
  14614. else
  14615. {
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14617. }
  14618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14619. isKnowKey = TRUE;
  14620. }
  14621. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14622. {
  14623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14625. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14626. {
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14628. }
  14629. else
  14630. {
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14632. }
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14634. isKnowKey = TRUE;
  14635. }
  14636. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14637. {
  14638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14640. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14641. {
  14642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14643. }
  14644. else
  14645. {
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14647. }
  14648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14649. isKnowKey = TRUE;
  14650. }
  14651. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14652. {
  14653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14655. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14656. {
  14657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14658. }
  14659. else
  14660. {
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14662. }
  14663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14664. isKnowKey = TRUE;
  14665. }
  14666. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14667. {
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14671. {
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14673. }
  14674. else
  14675. {
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14677. }
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14679. isKnowKey = TRUE;
  14680. }
  14681. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14682. {
  14683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14686. {
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14688. }
  14689. else
  14690. {
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14692. }
  14693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14694. isKnowKey = TRUE;
  14695. }
  14696. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14697. {
  14698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14701. {
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14703. }
  14704. else
  14705. {
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14707. }
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14709. isKnowKey = TRUE;
  14710. }
  14711. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14712. {
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14716. {
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14718. }
  14719. else
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14722. }
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14724. isKnowKey = TRUE;
  14725. }
  14726. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14727. {
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14730. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14731. {
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14733. }
  14734. else
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14737. }
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14739. isKnowKey = TRUE;
  14740. }
  14741. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14742. {
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14746. {
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14748. }
  14749. else
  14750. {
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14752. }
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14754. isKnowKey = TRUE;
  14755. }
  14756. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14757. {
  14758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14761. {
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14763. }
  14764. else
  14765. {
  14766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14767. }
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14769. isKnowKey = TRUE;
  14770. }
  14771. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14772. {
  14773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14775. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14776. {
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14778. }
  14779. else
  14780. {
  14781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14782. }
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14784. isKnowKey = TRUE;
  14785. }
  14786. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14787. {
  14788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14790. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14791. {
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14793. }
  14794. else
  14795. {
  14796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14797. }
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14799. isKnowKey = TRUE;
  14800. }
  14801. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14802. {
  14803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14805. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14806. {
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14808. }
  14809. else
  14810. {
  14811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14812. }
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14814. isKnowKey = TRUE;
  14815. }
  14816. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14817. {
  14818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14820. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14821. {
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14823. }
  14824. else
  14825. {
  14826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14827. }
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14829. isKnowKey = TRUE;
  14830. }
  14831. /*
  14832. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14833. {
  14834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14836. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14837. {
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14839. }
  14840. else
  14841. {
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14843. }
  14844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14845. isKnowKey = TRUE;
  14846. }*/
  14847. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14848. {
  14849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14851. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14852. {
  14853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14854. }
  14855. else
  14856. {
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14858. }
  14859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14860. isKnowKey = TRUE;
  14861. }
  14862. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14863. {
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14866. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14867. {
  14868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14869. }
  14870. else
  14871. {
  14872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14873. }
  14874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14875. isKnowKey = TRUE;
  14876. }
  14877. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14878. {
  14879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14881. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14882. {
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14884. }
  14885. else
  14886. {
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14888. }
  14889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14890. isKnowKey = TRUE;
  14891. }
  14892. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14893. {
  14894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14896. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14897. {
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14899. }
  14900. else
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14903. }
  14904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14905. isKnowKey = TRUE;
  14906. }
  14907. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14908. {
  14909. struct sysinfo s_info;
  14910. int error = sysinfo(&s_info);
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14914. {
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14916. }
  14917. else
  14918. {
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14920. }
  14921. if(error != 0)
  14922. {
  14923. DEBUG_WARN("System uptime get error: %d\n", error);
  14924. }
  14925. else
  14926. {
  14927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14928. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14929. }
  14930. isKnowKey = TRUE;
  14931. }
  14932. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14933. {
  14934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14937. {
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14939. }
  14940. else
  14941. {
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14943. }
  14944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14945. isKnowKey = TRUE;
  14946. }
  14947. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  14948. {
  14949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  14950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  14951. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  14952. {
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  14954. }
  14955. else
  14956. {
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  14958. }
  14959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14960. isKnowKey = TRUE;
  14961. }
  14962. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14963. {
  14964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14966. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14967. {
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14969. }
  14970. else
  14971. {
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14973. }
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14975. isKnowKey = TRUE;
  14976. }
  14977. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14978. {
  14979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14981. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14982. {
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14984. }
  14985. else
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14988. }
  14989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14990. isKnowKey = TRUE;
  14991. }
  14992. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14993. {
  14994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  14996. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  14997. {
  14998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  14999. }
  15000. else
  15001. {
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15003. }
  15004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15005. isKnowKey = TRUE;
  15006. }
  15007. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15008. {
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15011. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15012. {
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15014. }
  15015. else
  15016. {
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15018. }
  15019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15020. isKnowKey = TRUE;
  15021. }
  15022. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15023. {
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15026. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15027. {
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15029. }
  15030. else
  15031. {
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15033. }
  15034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15035. isKnowKey = TRUE;
  15036. }
  15037. #if 1
  15038. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15039. {
  15040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15042. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15043. {
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15045. }
  15046. else
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15049. }
  15050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15051. isKnowKey = TRUE;
  15052. }
  15053. #endif
  15054. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15055. {
  15056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15058. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15061. }
  15062. else
  15063. {
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15065. }
  15066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15067. isKnowKey = TRUE;
  15068. }
  15069. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15070. {
  15071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15073. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15076. }
  15077. else
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15080. }
  15081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15082. isKnowKey = TRUE;
  15083. }
  15084. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15085. {
  15086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15088. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15089. {
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15091. }
  15092. else
  15093. {
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15095. }
  15096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15097. isKnowKey = TRUE;
  15098. }
  15099. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15100. {
  15101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15103. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15104. {
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15106. }
  15107. else
  15108. {
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15110. }
  15111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15112. isKnowKey = TRUE;
  15113. }
  15114. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15115. {
  15116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15118. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15119. {
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15121. }
  15122. else
  15123. {
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15125. }
  15126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15127. isKnowKey = TRUE;
  15128. }
  15129. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15130. {
  15131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15133. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15134. {
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15136. }
  15137. else
  15138. {
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15140. }
  15141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15142. isKnowKey = TRUE;
  15143. }
  15144. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15145. {
  15146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15148. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15149. {
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15151. }
  15152. else
  15153. {
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15155. }
  15156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15157. isKnowKey = TRUE;
  15158. }
  15159. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15160. {
  15161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15163. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15164. {
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15166. }
  15167. else
  15168. {
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15170. }
  15171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15172. isKnowKey = TRUE;
  15173. }
  15174. //=========================================================
  15175. if(!isEmpty && !isKnowKey)
  15176. {
  15177. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15178. strcpy(unknownkey[UnknownKeynum], keyReq);
  15179. UnknownKeynum = UnknownKeynum + 1;
  15180. }
  15181. }
  15182. void processUnkownKey(void)
  15183. {
  15184. DEBUG_INFO("processUnkownKey...\n");
  15185. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15186. for(int index=0; index < UnknownKeynum; index++)
  15187. {
  15188. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15189. {
  15190. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15191. }
  15192. }
  15193. }
  15194. int setKeyValue(char *key, char *value)
  15195. {
  15196. int isSuccess = NotSupported;
  15197. int check_ascii=0;
  15198. char str[501]={0};
  15199. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15200. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15201. {
  15202. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15203. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15204. {
  15205. strcpy(str, (const char*)value);
  15206. for(int i = 0; str[i]; i++){
  15207. str[i] = tolower(str[i]);
  15208. }
  15209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15210. isSuccess = ConfigurationStatus_Accepted;
  15211. }
  15212. else
  15213. {
  15214. isSuccess = ConfigurationStatus_Rejected;
  15215. }
  15216. }
  15217. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15218. {
  15219. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15220. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15221. {
  15222. strcpy(str, (const char*)value);
  15223. for(int i = 0; str[i]; i++){
  15224. str[i] = tolower(str[i]);
  15225. }
  15226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15227. isSuccess = ConfigurationStatus_Accepted;
  15228. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15229. }
  15230. else
  15231. {
  15232. isSuccess = ConfigurationStatus_Rejected;
  15233. }
  15234. }
  15235. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15236. {
  15237. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15238. {
  15239. strcpy(str, (const char*)value);
  15240. for(int i = 0; str[i]; i++)
  15241. {
  15242. str[i] = tolower(str[i]);
  15243. }
  15244. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15246. isSuccess = ConfigurationStatus_Accepted;
  15247. }
  15248. else
  15249. {
  15250. isSuccess = ConfigurationStatus_Rejected;
  15251. }
  15252. }
  15253. if(strcmp(key, "BlinkRepeat") == 0)
  15254. {
  15255. //Charger.BlinkRepeat = Integer.parseInt(value);
  15256. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15257. {
  15258. check_ascii = value[0];
  15259. if( (check_ascii < 48) || (check_ascii > 57) )
  15260. {
  15261. isSuccess = ConfigurationStatus_Rejected;
  15262. }
  15263. else
  15264. {
  15265. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15266. isSuccess = ConfigurationStatus_Accepted;
  15267. }
  15268. }
  15269. else
  15270. {
  15271. isSuccess = ConfigurationStatus_Rejected;
  15272. }
  15273. }
  15274. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15275. {
  15276. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15277. {
  15278. check_ascii = value[0];
  15279. if( (check_ascii < 48) || (check_ascii > 57) )
  15280. {
  15281. isSuccess = ConfigurationStatus_Rejected;
  15282. }
  15283. else
  15284. {
  15285. if((atoi(value) == 0) || (atoi(value) >= 5))
  15286. {
  15287. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15289. isSuccess = ConfigurationStatus_Accepted;
  15290. }
  15291. else
  15292. isSuccess = ConfigurationStatus_Rejected;
  15293. }
  15294. }
  15295. else
  15296. {
  15297. isSuccess = ConfigurationStatus_Rejected;
  15298. }
  15299. }
  15300. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15301. {
  15302. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15303. {
  15304. check_ascii = value[0];
  15305. if( (check_ascii < 48) || (check_ascii > 57) )
  15306. {
  15307. isSuccess = ConfigurationStatus_Rejected;
  15308. }
  15309. else
  15310. {
  15311. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15313. isSuccess = ConfigurationStatus_Accepted;
  15314. }
  15315. }
  15316. else
  15317. {
  15318. isSuccess = ConfigurationStatus_Rejected;
  15319. }
  15320. }
  15321. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15322. {
  15323. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15324. {
  15325. check_ascii = value[0];
  15326. if( (check_ascii < 48) || (check_ascii > 57) )
  15327. {
  15328. isSuccess = ConfigurationStatus_Rejected;
  15329. }
  15330. else
  15331. {
  15332. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15334. isSuccess = ConfigurationStatus_Accepted;
  15335. }
  15336. }
  15337. else
  15338. {
  15339. isSuccess = ConfigurationStatus_Rejected;
  15340. }
  15341. }
  15342. if(strcmp(key, "HeartbeatInterval") == 0)
  15343. {
  15344. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15345. {
  15346. check_ascii = value[0];
  15347. if( (check_ascii < 48) || (check_ascii > 57) )
  15348. {
  15349. isSuccess = ConfigurationStatus_Rejected;
  15350. }
  15351. else
  15352. {
  15353. if((atoi(value) == 0) || (atoi(value) >= 10))
  15354. {
  15355. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15356. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15357. HeartBeatWaitTime = atoi(value);
  15358. isSuccess = ConfigurationStatus_Accepted;
  15359. }
  15360. else
  15361. {
  15362. isSuccess = ConfigurationStatus_Rejected;
  15363. }
  15364. }
  15365. }
  15366. else
  15367. {
  15368. isSuccess = ConfigurationStatus_Rejected;
  15369. }
  15370. }
  15371. if(strcmp(key, "LightIntensity") == 0)
  15372. {
  15373. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15374. {
  15375. check_ascii = value[0];
  15376. if( (check_ascii < 48) || (check_ascii > 57) )
  15377. {
  15378. isSuccess = ConfigurationStatus_Rejected;
  15379. }
  15380. else
  15381. {
  15382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15383. isSuccess = ConfigurationStatus_Accepted;
  15384. }
  15385. }
  15386. else
  15387. {
  15388. isSuccess = ConfigurationStatus_Rejected;
  15389. }
  15390. }
  15391. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15392. {
  15393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15394. {
  15395. strcpy(str, (const char*)value);
  15396. for(int i = 0; str[i]; i++)
  15397. {
  15398. str[i] = tolower(str[i]);
  15399. }
  15400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15401. isSuccess = ConfigurationStatus_Accepted;
  15402. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15403. }
  15404. else
  15405. {
  15406. isSuccess = ConfigurationStatus_Rejected;
  15407. }
  15408. }
  15409. if(strcmp(key, "LocalPreAuthorize") == 0)
  15410. {
  15411. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15412. {
  15413. strcpy(str, (const char*)value);
  15414. for(int i = 0; str[i]; i++)
  15415. {
  15416. str[i] = tolower(str[i]);
  15417. }
  15418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15419. isSuccess = ConfigurationStatus_Accepted;
  15420. }
  15421. else
  15422. {
  15423. isSuccess = ConfigurationStatus_Rejected;
  15424. }
  15425. }
  15426. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15427. {
  15428. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15429. {
  15430. check_ascii = value[0];
  15431. if( (check_ascii < 48) || (check_ascii > 57) )
  15432. {
  15433. isSuccess = ConfigurationStatus_Rejected;
  15434. }
  15435. else
  15436. {
  15437. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15438. isSuccess = ConfigurationStatus_Accepted;
  15439. }
  15440. }
  15441. else
  15442. {
  15443. isSuccess = ConfigurationStatus_Rejected;
  15444. }
  15445. }
  15446. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15447. {
  15448. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15449. {
  15450. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15451. isSuccess = ConfigurationStatus_Accepted;
  15452. }
  15453. else
  15454. {
  15455. isSuccess = ConfigurationStatus_Rejected;
  15456. }
  15457. }
  15458. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15459. {
  15460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15461. {
  15462. check_ascii = value[0];
  15463. if( (check_ascii < 48) || (check_ascii > 57) )
  15464. {
  15465. isSuccess = ConfigurationStatus_Rejected;
  15466. }
  15467. else
  15468. {
  15469. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15470. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15471. isSuccess = ConfigurationStatus_Accepted;
  15472. }
  15473. }
  15474. else
  15475. {
  15476. isSuccess = ConfigurationStatus_Rejected;
  15477. }
  15478. }
  15479. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15480. {
  15481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15482. {
  15483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15484. isSuccess = ConfigurationStatus_Accepted;
  15485. }
  15486. else
  15487. {
  15488. isSuccess = ConfigurationStatus_Rejected;
  15489. }
  15490. }
  15491. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15492. {
  15493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15494. {
  15495. check_ascii = value[0];
  15496. if( (check_ascii < 48) || (check_ascii > 57) )
  15497. {
  15498. isSuccess = ConfigurationStatus_Rejected;
  15499. }
  15500. else
  15501. {
  15502. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15504. isSuccess = ConfigurationStatus_Accepted;
  15505. }
  15506. }
  15507. else
  15508. {
  15509. isSuccess = ConfigurationStatus_Rejected;
  15510. }
  15511. }
  15512. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15513. {
  15514. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15515. {
  15516. check_ascii = value[0];
  15517. if( (check_ascii < 48) || (check_ascii > 57) )
  15518. {
  15519. isSuccess = ConfigurationStatus_Rejected;
  15520. }
  15521. else
  15522. {
  15523. if((atoi(value) == 0) || (atoi(value) >= 3))
  15524. {
  15525. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15527. isSuccess = ConfigurationStatus_Accepted;
  15528. }
  15529. else
  15530. {
  15531. isSuccess = ConfigurationStatus_Rejected;
  15532. }
  15533. }
  15534. }
  15535. else
  15536. {
  15537. isSuccess = ConfigurationStatus_Rejected;
  15538. }
  15539. }
  15540. if(strcmp(key, "MinimumStatusDuration") == 0)
  15541. {
  15542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15543. {
  15544. check_ascii = value[0];
  15545. if( (check_ascii < 48) || (check_ascii > 57) )
  15546. {
  15547. isSuccess = ConfigurationStatus_Rejected;
  15548. }
  15549. else
  15550. {
  15551. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15552. {
  15553. isSuccess = ConfigurationStatus_Rejected;
  15554. }
  15555. else
  15556. {
  15557. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15559. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15560. isSuccess = ConfigurationStatus_Accepted;
  15561. }
  15562. }
  15563. }
  15564. else
  15565. {
  15566. isSuccess = ConfigurationStatus_Rejected;
  15567. }
  15568. }
  15569. if(strcmp(key, "NumberOfConnectors") == 0)
  15570. {
  15571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15572. {
  15573. check_ascii = value[0];
  15574. if( (check_ascii < 48) || (check_ascii > 57) )
  15575. {
  15576. isSuccess = ConfigurationStatus_Rejected;
  15577. }
  15578. else
  15579. {
  15580. //Charger.ResetRetries = Integer.parseInt(value);
  15581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15582. isSuccess = ConfigurationStatus_Accepted;
  15583. }
  15584. }
  15585. else
  15586. {
  15587. isSuccess = ConfigurationStatus_Rejected;
  15588. }
  15589. }
  15590. if(strcmp(key, "ResetRetries") == 0)
  15591. {
  15592. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15593. {
  15594. check_ascii = value[0];
  15595. if( (check_ascii < 48) || (check_ascii > 57) )
  15596. {
  15597. isSuccess = ConfigurationStatus_Rejected;
  15598. }
  15599. else
  15600. {
  15601. //Charger.ResetRetries = Integer.parseInt(value);
  15602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15603. isSuccess = ConfigurationStatus_Accepted;
  15604. }
  15605. }
  15606. else
  15607. {
  15608. isSuccess = ConfigurationStatus_Rejected;
  15609. }
  15610. }
  15611. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15612. {
  15613. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15614. {
  15615. strcpy(str, (const char*)value);
  15616. for(int i = 0; str[i]; i++)
  15617. {
  15618. str[i] = tolower(str[i]);
  15619. }
  15620. if(strcmp(str, "notapplicable")== 0)
  15621. {
  15622. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15623. isSuccess = ConfigurationStatus_Accepted;
  15624. }
  15625. else if(strcmp(str, "unknown")== 0)
  15626. {
  15627. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15628. isSuccess = ConfigurationStatus_Accepted;
  15629. }
  15630. else if(strcmp(str, "rst")== 0)
  15631. {
  15632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15633. isSuccess = ConfigurationStatus_Accepted;
  15634. }
  15635. else if(strcmp(str, "rts")== 0)
  15636. {
  15637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15638. isSuccess = ConfigurationStatus_Accepted;
  15639. }
  15640. else if(strcmp(str, "srt")== 0)
  15641. {
  15642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15643. isSuccess = ConfigurationStatus_Accepted;
  15644. }
  15645. else if(strcmp(str, "str")== 0)
  15646. {
  15647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15648. isSuccess = ConfigurationStatus_Accepted;
  15649. }
  15650. else if(strcmp(str, "trs")== 0)
  15651. {
  15652. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15653. isSuccess = ConfigurationStatus_Accepted;
  15654. }
  15655. else if(strcmp(str, "tsr")== 0)
  15656. {
  15657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15658. isSuccess = ConfigurationStatus_Accepted;
  15659. }
  15660. else
  15661. {
  15662. isSuccess = ConfigurationStatus_Rejected;
  15663. }
  15664. }
  15665. else
  15666. {
  15667. isSuccess = ConfigurationStatus_Rejected;
  15668. }
  15669. }
  15670. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15671. {
  15672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15673. {
  15674. check_ascii = value[0];
  15675. if( (check_ascii < 48) || (check_ascii > 57) )
  15676. {
  15677. isSuccess = ConfigurationStatus_Rejected;
  15678. }
  15679. else
  15680. {
  15681. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15682. isSuccess = ConfigurationStatus_Accepted;
  15683. }
  15684. }
  15685. else
  15686. {
  15687. isSuccess = ConfigurationStatus_Rejected;
  15688. }
  15689. }
  15690. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15691. {
  15692. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15693. {
  15694. strcpy(str, (const char*)value);
  15695. for(int i = 0; str[i]; i++)
  15696. {
  15697. str[i] = tolower(str[i]);
  15698. }
  15699. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15701. isSuccess = ConfigurationStatus_Accepted;
  15702. }
  15703. else
  15704. {
  15705. isSuccess = ConfigurationStatus_Rejected;
  15706. }
  15707. }
  15708. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15709. {
  15710. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15711. {
  15712. strcpy(str, (const char*)value);
  15713. for(int i = 0; str[i]; i++)
  15714. {
  15715. str[i] = tolower(str[i]);
  15716. }
  15717. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15719. isSuccess = ConfigurationStatus_Accepted;
  15720. }
  15721. else
  15722. {
  15723. isSuccess = ConfigurationStatus_Rejected;
  15724. }
  15725. }
  15726. if(strcmp(key, "StopTxnAlignedData") == 0)
  15727. {
  15728. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15729. {
  15730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15731. isSuccess = ConfigurationStatus_Accepted;
  15732. }
  15733. else
  15734. {
  15735. isSuccess = ConfigurationStatus_Rejected;
  15736. }
  15737. }
  15738. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15739. {
  15740. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15741. {
  15742. check_ascii = value[0];
  15743. if( (check_ascii < 48) || (check_ascii > 57) )
  15744. {
  15745. isSuccess = ConfigurationStatus_Rejected;
  15746. }
  15747. else
  15748. {
  15749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15750. isSuccess = ConfigurationStatus_Accepted;
  15751. }
  15752. }
  15753. else
  15754. {
  15755. isSuccess = ConfigurationStatus_Rejected;
  15756. }
  15757. }
  15758. if(strcmp(key, "StopTxnSampledData") == 0)
  15759. {
  15760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15761. {
  15762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15763. isSuccess = ConfigurationStatus_Accepted;
  15764. }
  15765. else
  15766. {
  15767. isSuccess = ConfigurationStatus_Rejected;
  15768. }
  15769. }
  15770. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15771. {
  15772. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15773. {
  15774. check_ascii = value[0];
  15775. if( (check_ascii < 48) || (check_ascii > 57) )
  15776. {
  15777. isSuccess = ConfigurationStatus_Rejected;
  15778. }
  15779. else
  15780. {
  15781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15782. isSuccess = ConfigurationStatus_Accepted;
  15783. }
  15784. }
  15785. else
  15786. {
  15787. isSuccess = ConfigurationStatus_Rejected;
  15788. }
  15789. }
  15790. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15791. {
  15792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15793. {
  15794. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15795. isSuccess = ConfigurationStatus_Accepted;
  15796. }
  15797. else
  15798. {
  15799. isSuccess = ConfigurationStatus_Rejected;
  15800. }
  15801. }
  15802. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15803. {
  15804. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15805. {
  15806. check_ascii = value[0];
  15807. if( (check_ascii < 48) || (check_ascii > 57) )
  15808. {
  15809. isSuccess = ConfigurationStatus_Rejected;
  15810. }
  15811. else
  15812. {
  15813. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15814. isSuccess = ConfigurationStatus_Accepted;
  15815. }
  15816. }
  15817. else
  15818. {
  15819. isSuccess = ConfigurationStatus_Rejected;
  15820. }
  15821. }
  15822. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15823. {
  15824. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15825. {
  15826. check_ascii = value[0];
  15827. if( (check_ascii < 48) || (check_ascii > 57) )
  15828. {
  15829. isSuccess = ConfigurationStatus_Rejected;
  15830. }
  15831. else
  15832. {
  15833. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15835. TransactionMessageAttemptsValue = atoi(value);
  15836. isSuccess = ConfigurationStatus_Accepted;
  15837. }
  15838. }
  15839. else
  15840. {
  15841. isSuccess = ConfigurationStatus_Rejected;
  15842. }
  15843. }
  15844. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15845. {
  15846. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15847. {
  15848. check_ascii = value[0];
  15849. if( (check_ascii < 48) || (check_ascii > 57) )
  15850. {
  15851. isSuccess = ConfigurationStatus_Rejected;
  15852. }
  15853. else
  15854. {
  15855. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15857. TransactionMessageRetryIntervalValue = atoi(value);
  15858. isSuccess = ConfigurationStatus_Accepted;
  15859. }
  15860. }
  15861. else
  15862. {
  15863. isSuccess = ConfigurationStatus_Rejected;
  15864. }
  15865. }
  15866. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15867. {
  15868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15869. {
  15870. strcpy(str, (const char*)value);
  15871. for(int i = 0; str[i]; i++)
  15872. {
  15873. str[i] = tolower(str[i]);
  15874. }
  15875. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15877. isSuccess = ConfigurationStatus_Accepted;
  15878. }
  15879. else
  15880. {
  15881. isSuccess = ConfigurationStatus_Rejected;
  15882. }
  15883. }
  15884. if(strcmp(key, "WebSocketPingInterval") == 0)
  15885. {
  15886. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15887. {
  15888. check_ascii = value[0];
  15889. if( (check_ascii < 48) || (check_ascii > 57) )
  15890. {
  15891. isSuccess = ConfigurationStatus_Rejected;
  15892. }
  15893. else
  15894. {
  15895. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15896. isSuccess = ConfigurationStatus_Accepted;
  15897. if((atoi(value) == 0) || (atoi(value) >= 10))
  15898. {
  15899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15900. isSuccess = ConfigurationStatus_Accepted;
  15901. }
  15902. else
  15903. isSuccess = ConfigurationStatus_Rejected;
  15904. }
  15905. }
  15906. else
  15907. {
  15908. isSuccess = ConfigurationStatus_Rejected;
  15909. }
  15910. }
  15911. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15912. {
  15913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15914. {
  15915. strcpy(str, (const char*)value);
  15916. for(int i = 0; str[i]; i++)
  15917. {
  15918. str[i] = tolower(str[i]);
  15919. }
  15920. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15921. isSuccess = ConfigurationStatus_Accepted;
  15922. }
  15923. else
  15924. {
  15925. isSuccess = ConfigurationStatus_Rejected;
  15926. }
  15927. }
  15928. if(strcmp(key, "AuthorizationKey") == 0)
  15929. {
  15930. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15931. {
  15932. strcpy(str, (const char*)value);
  15933. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15934. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15935. isSuccess = ConfigurationStatus_Accepted;
  15936. }
  15937. else
  15938. {
  15939. isSuccess = ConfigurationStatus_Rejected;
  15940. }
  15941. }
  15942. if(strcmp(key, "SecurityProfile") == 0)
  15943. {
  15944. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15945. {
  15946. check_ascii = value[0];
  15947. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. else if(check_ascii == 0x33)
  15952. {
  15953. isSuccess = NotSupported;
  15954. }
  15955. else
  15956. {
  15957. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15958. {
  15959. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15960. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15961. isSuccess = ConfigurationStatus_Accepted;
  15962. }
  15963. else
  15964. isSuccess = ConfigurationStatus_Rejected;
  15965. }
  15966. }
  15967. else
  15968. {
  15969. isSuccess = ConfigurationStatus_Rejected;
  15970. }
  15971. }
  15972. if(strcmp(key, "DefaultPrice") == 0)
  15973. {
  15974. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15975. {
  15976. strcpy(str, (const char*)value);
  15977. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15978. isSuccess = ConfigurationStatus_Accepted;
  15979. }
  15980. else
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. }
  15985. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15986. {
  15987. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15988. {
  15989. strcpy(str, (const char*)value);
  15990. for(int i = 0; str[i]; i++)
  15991. {
  15992. str[i] = tolower(str[i]);
  15993. }
  15994. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15995. isSuccess = ConfigurationStatus_Accepted;
  15996. }
  15997. else
  15998. {
  15999. isSuccess = ConfigurationStatus_Rejected;
  16000. }
  16001. }
  16002. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16003. {
  16004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16005. {
  16006. strcpy(str, (const char*)value);
  16007. for(int i = 0; str[i]; i++)
  16008. {
  16009. str[i] = tolower(str[i]);
  16010. }
  16011. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16012. isSuccess = ConfigurationStatus_Accepted;
  16013. }
  16014. else
  16015. {
  16016. isSuccess = ConfigurationStatus_Rejected;
  16017. }
  16018. }
  16019. if(strcmp(key, "SystemUptimeSec") == 0)
  16020. {
  16021. isSuccess = NotSupported;
  16022. }
  16023. if(strcmp(key, "FreeVend") == 0)
  16024. {
  16025. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16026. {
  16027. strcpy(str, (const char*)value);
  16028. for(int i = 0; str[i]; i++)
  16029. {
  16030. str[i] = tolower(str[i]);
  16031. }
  16032. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16034. isSuccess = ConfigurationStatus_Accepted;
  16035. }
  16036. else
  16037. {
  16038. isSuccess = ConfigurationStatus_Rejected;
  16039. }
  16040. }
  16041. if(strcmp(key, "FreeVendIdtag") == 0)
  16042. {
  16043. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16044. {
  16045. strcpy(str, (const char*)value);
  16046. if(strlen(str) <= 20)
  16047. {
  16048. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16049. isSuccess = ConfigurationStatus_Accepted;
  16050. }
  16051. else
  16052. {
  16053. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16054. isSuccess = ConfigurationStatus_Rejected;
  16055. }
  16056. }
  16057. else
  16058. {
  16059. isSuccess = ConfigurationStatus_Rejected;
  16060. }
  16061. }
  16062. if(strcmp(key, "OcppServer") == 0)
  16063. {
  16064. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16065. {
  16066. strcpy(str, (const char*)value);
  16067. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16068. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16069. isSuccess = ConfigurationStatus_Accepted;
  16070. }
  16071. else
  16072. {
  16073. isSuccess = ConfigurationStatus_Rejected;
  16074. }
  16075. }
  16076. if(strcmp(key, "MaintainServer") == 0)
  16077. {
  16078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16079. {
  16080. strcpy(str, (const char*)value);
  16081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16082. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16083. isSuccess = ConfigurationStatus_Accepted;
  16084. }
  16085. else
  16086. {
  16087. isSuccess = ConfigurationStatus_Rejected;
  16088. }
  16089. }
  16090. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16091. {
  16092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16093. {
  16094. strcpy(str, (const char*)value);
  16095. for(int i = 0; str[i]; i++)
  16096. {
  16097. str[i] = tolower(str[i]);
  16098. }
  16099. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16100. isSuccess = ConfigurationStatus_Accepted;
  16101. }
  16102. else
  16103. {
  16104. isSuccess = ConfigurationStatus_Rejected;
  16105. }
  16106. }
  16107. if(strcmp(key, "StatusNotificationInterval") == 0)
  16108. {
  16109. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16110. {
  16111. check_ascii = value[0];
  16112. if( (check_ascii < 48) || (check_ascii > 57) )
  16113. {
  16114. isSuccess = ConfigurationStatus_Rejected;
  16115. }
  16116. else
  16117. {
  16118. if((atoi(value) == 0) || (atoi(value) >= 10))
  16119. {
  16120. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16121. isSuccess = ConfigurationStatus_Accepted;
  16122. }
  16123. else
  16124. isSuccess = ConfigurationStatus_Rejected;
  16125. }
  16126. }
  16127. else
  16128. {
  16129. isSuccess = ConfigurationStatus_Rejected;
  16130. }
  16131. }
  16132. #if 0
  16133. //For OCPP Test Case
  16134. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16135. {
  16136. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16137. {
  16138. strcpy(str, (const char*)value);
  16139. for(int i = 0; str[i]; i++)
  16140. {
  16141. str[i] = tolower(str[i]);
  16142. }
  16143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16144. isSuccess = ConfigurationStatus_Accepted;
  16145. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16146. }
  16147. else
  16148. {
  16149. isSuccess = ConfigurationStatus_Rejected;
  16150. }
  16151. }
  16152. #endif
  16153. #if 1
  16154. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16155. {
  16156. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16157. {
  16158. strcpy(str, (const char*)value);
  16159. for(int i = 0; str[i]; i++)
  16160. {
  16161. str[i] = tolower(str[i]);
  16162. }
  16163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16164. isSuccess = ConfigurationStatus_Accepted;
  16165. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16166. }
  16167. else
  16168. {
  16169. isSuccess = ConfigurationStatus_Rejected;
  16170. }
  16171. }
  16172. #endif
  16173. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16174. {
  16175. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16176. {
  16177. check_ascii = value[0];
  16178. if( (check_ascii < 48) || (check_ascii > 57) )
  16179. {
  16180. isSuccess = ConfigurationStatus_Rejected;
  16181. }
  16182. else
  16183. {
  16184. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16185. isSuccess = ConfigurationStatus_Accepted;
  16186. }
  16187. }
  16188. else
  16189. {
  16190. isSuccess = ConfigurationStatus_Rejected;
  16191. }
  16192. }
  16193. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16194. {
  16195. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16196. {
  16197. check_ascii = value[0];
  16198. if( (check_ascii < 48) || (check_ascii > 57) )
  16199. {
  16200. isSuccess = ConfigurationStatus_Rejected;
  16201. }
  16202. else
  16203. {
  16204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16205. isSuccess = ConfigurationStatus_Accepted;
  16206. }
  16207. }
  16208. else
  16209. {
  16210. isSuccess = ConfigurationStatus_Rejected;
  16211. }
  16212. }
  16213. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16214. {
  16215. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16216. {
  16217. strcpy(str, (const char*)value);
  16218. for(int i = 0; str[i]; i++)
  16219. {
  16220. str[i] = tolower(str[i]);
  16221. }
  16222. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16223. isSuccess = ConfigurationStatus_Accepted;
  16224. }
  16225. else
  16226. {
  16227. isSuccess = ConfigurationStatus_Rejected;
  16228. }
  16229. }
  16230. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16231. {
  16232. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16233. {
  16234. check_ascii = value[0];
  16235. if( (check_ascii < 48) || (check_ascii > 57) )
  16236. {
  16237. isSuccess = ConfigurationStatus_Rejected;
  16238. }
  16239. else
  16240. {
  16241. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16242. isSuccess = ConfigurationStatus_Accepted;
  16243. }
  16244. }
  16245. else
  16246. {
  16247. isSuccess = ConfigurationStatus_Rejected;
  16248. }
  16249. }
  16250. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16251. {
  16252. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16253. {
  16254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16255. isSuccess = ConfigurationStatus_Accepted;
  16256. }
  16257. else
  16258. {
  16259. isSuccess = ConfigurationStatus_Rejected;
  16260. }
  16261. }
  16262. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16263. {
  16264. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16265. {
  16266. check_ascii = value[0];
  16267. if( (check_ascii < 48) || (check_ascii > 57) )
  16268. {
  16269. isSuccess = ConfigurationStatus_Rejected;
  16270. }
  16271. else
  16272. {
  16273. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16274. isSuccess = ConfigurationStatus_Accepted;
  16275. }
  16276. }
  16277. else
  16278. {
  16279. isSuccess = ConfigurationStatus_Rejected;
  16280. }
  16281. }
  16282. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16283. {
  16284. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16285. {
  16286. strcpy(str, (const char*)value);
  16287. for(int i = 0; str[i]; i++)
  16288. {
  16289. str[i] = tolower(str[i]);
  16290. }
  16291. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16292. isSuccess = ConfigurationStatus_Accepted;
  16293. }
  16294. else
  16295. {
  16296. isSuccess = ConfigurationStatus_Rejected;
  16297. }
  16298. }
  16299. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16300. {
  16301. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16302. {
  16303. check_ascii = value[0];
  16304. if( (check_ascii < 48) || (check_ascii > 57) )
  16305. {
  16306. isSuccess = ConfigurationStatus_Rejected;
  16307. }
  16308. else
  16309. {
  16310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16311. isSuccess = ConfigurationStatus_Accepted;
  16312. }
  16313. }
  16314. else
  16315. {
  16316. isSuccess = ConfigurationStatus_Rejected;
  16317. }
  16318. }
  16319. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16320. return isSuccess;
  16321. }
  16322. int TransactionMessageAttemptsGet(void)
  16323. {
  16324. return TransactionMessageAttemptsValue;
  16325. }
  16326. int FirstHeartBeatResponse(void)
  16327. {
  16328. return FirstHeartBeat;
  16329. }
  16330. int TransactionMessageRetryIntervalGet(void)
  16331. {
  16332. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16333. }
  16334. int ReadHttpStatus(int sock)
  16335. {
  16336. //char c;
  16337. char buff[1024]="",*ptr=buff+1;
  16338. int bytes_received, status;
  16339. DEBUG_INFO("Begin Response ..\n");
  16340. while((bytes_received = recv(sock, ptr, 1, 0))){
  16341. if(bytes_received==-1){
  16342. perror("ReadHttpStatus");
  16343. exit(1);
  16344. }
  16345. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16346. ptr++;
  16347. }
  16348. *ptr=0;
  16349. ptr=buff+1;
  16350. sscanf(ptr,"%*s %d ", &status);
  16351. DEBUG_INFO("%s\n",ptr);
  16352. DEBUG_INFO("status=%d\n",status);
  16353. DEBUG_INFO("End Response ..\n");
  16354. return (bytes_received>0)?status:0;
  16355. }
  16356. //the only filed that it parsed is 'Content-Length'
  16357. int ParseHeader(int sock)
  16358. {
  16359. //char c;
  16360. char buff[1024]="",*ptr=buff+4;
  16361. int bytes_received;
  16362. DEBUG_INFO("Begin HEADER ..\n");
  16363. while((bytes_received = recv(sock, ptr, 1, 0))){
  16364. if(bytes_received==-1){
  16365. perror("Parse Header");
  16366. exit(1);
  16367. }
  16368. if(
  16369. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16370. (ptr[-1]=='\r') && (*ptr=='\n' )
  16371. ) break;
  16372. ptr++;
  16373. }
  16374. *ptr=0;
  16375. ptr=buff+4;
  16376. //printf("%s",ptr);
  16377. if(bytes_received){
  16378. ptr=strstr(ptr,"Content-Length:");
  16379. if(ptr){
  16380. sscanf(ptr,"%*s %d",&bytes_received);
  16381. }else
  16382. bytes_received=-1; //unknown size
  16383. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16384. }
  16385. DEBUG_INFO("End HEADER ..\n");
  16386. return bytes_received ;
  16387. }
  16388. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16389. {
  16390. int result = TRUE;
  16391. char rmFileCmd[100]={0};
  16392. char FilePath[100]={0};
  16393. char ftpbuf[200];
  16394. int systemresult;
  16395. sprintf(FilePath,"/mnt/%s",filename);
  16396. system("ping 8.8.8.8 &");
  16397. if((access(FilePath,F_OK))!=-1)
  16398. {
  16399. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16400. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16401. system(rmFileCmd);
  16402. }
  16403. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16404. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16405. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16406. systemresult = system(ftpbuf);
  16407. if(systemresult != 0)
  16408. {
  16409. DEBUG_INFO("http DownLoad error!\n");
  16410. result = FALSE;
  16411. }
  16412. system("pkill ping");
  16413. return result;
  16414. }
  16415. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16416. {
  16417. int result = TRUE;
  16418. char rmFileCmd[100]={0};
  16419. char FilePath[100]={0};
  16420. char ftpbuf[200];
  16421. int systemresult;
  16422. sprintf(FilePath,"/mnt/%s",filename);
  16423. system("ping 8.8.8.8 &");
  16424. if((access(FilePath,F_OK))!=-1)
  16425. {
  16426. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16427. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16428. system(rmFileCmd);
  16429. }
  16430. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16431. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16432. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16433. systemresult = system(ftpbuf);
  16434. if(systemresult != 0)
  16435. {
  16436. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16437. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16438. systemresult = system(ftpbuf);
  16439. if(systemresult != 0)
  16440. {
  16441. DEBUG_WARN("wget error!\n");
  16442. result = FALSE;
  16443. }
  16444. }
  16445. system("pkill ping");
  16446. return result;
  16447. }
  16448. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16449. {
  16450. char rmFileCmd[100]={0};
  16451. char FilePath[100]={0};
  16452. char buf[512];
  16453. int systemresult = 0;
  16454. //DEBUG_INFO("filename=%s\n",filename);
  16455. //DEBUG_INFO("url=%s\n",url);
  16456. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16457. if((access(FilePath,F_OK))!=-1)
  16458. {
  16459. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16460. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16461. system(rmFileCmd);
  16462. }
  16463. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16464. if(fp == NULL)
  16465. {
  16466. DEBUG_INFO("log is NULL\n");
  16467. return FALSE;
  16468. }
  16469. else
  16470. {
  16471. fprintf(fp, "%s\n", url);
  16472. fprintf(fp, "%s\n", filename);
  16473. fclose(fp);
  16474. }
  16475. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16476. if(phpFP == NULL)
  16477. {
  16478. DEBUG_INFO("PHP upload fail.\n");
  16479. return FALSE;
  16480. }
  16481. else
  16482. {
  16483. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16484. {
  16485. if(strstr(buf, "result") != NULL)
  16486. {
  16487. sscanf(buf, "result: %d", &systemresult);
  16488. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16489. }
  16490. }
  16491. pclose(phpFP);
  16492. }
  16493. if(systemresult != 1)
  16494. {
  16495. DEBUG_INFO("HTTP upload error!\n");
  16496. return FALSE;
  16497. }
  16498. return TRUE;
  16499. }
  16500. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16501. {
  16502. int result = FALSE;
  16503. char ftpbuf[200];
  16504. int systemresult;
  16505. /*
  16506. // Domaind name transfer to IP address
  16507. struct hostent* server;
  16508. char *IPbuffer;
  16509. server = gethostbyname(location);
  16510. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16511. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16512. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16513. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16514. systemresult = system(ftpbuf);
  16515. if(systemresult != 0)
  16516. {
  16517. DEBUG_INFO("ftpput error!\n");
  16518. }
  16519. else
  16520. {
  16521. result = TRUE;
  16522. DEBUG_INFO("ftpput OK!\n");
  16523. }
  16524. return result;
  16525. }
  16526. int GetOcppServerURL()
  16527. {
  16528. int result = FALSE;
  16529. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16530. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16531. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16532. struct yuarel url;
  16533. char urlStr[512];
  16534. // OCPPPH only
  16535. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16536. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16537. {
  16538. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16539. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16540. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16541. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16542. if(yuarel_parse(&url, urlStr) != -1)
  16543. {
  16544. sprintf(OcppProtocol, "%s", url.scheme);
  16545. sprintf(OcppHost, "%s", url.host);
  16546. if(url.path == NULL)
  16547. OcppTempPath[0] = '\0';
  16548. else
  16549. sprintf(OcppTempPath, "%s", url.path);
  16550. if(url.port == 0)
  16551. {
  16552. if(strcmp(OcppProtocol, "wss") == 0)
  16553. OcppPort = 443;
  16554. else
  16555. OcppPort = 80;
  16556. }
  16557. else
  16558. OcppPort = url.port;
  16559. result = TRUE;
  16560. }
  16561. }
  16562. else
  16563. {
  16564. strcpy(OcppHost,"");
  16565. }
  16566. return result;
  16567. }
  16568. int GetOcppPath()
  16569. {
  16570. int result = FALSE;
  16571. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16572. {
  16573. if(OcppTempPath == NULL)
  16574. {
  16575. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16576. }
  16577. else
  16578. {
  16579. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16580. }
  16581. result = TRUE;
  16582. goto End;
  16583. }
  16584. else
  16585. {
  16586. strcpy(OcppPath,"");
  16587. }
  16588. End:
  16589. return result;
  16590. }
  16591. int GetOcppPort()
  16592. {
  16593. return OcppPort;
  16594. }
  16595. int GetOcppConnStatus(void)
  16596. {
  16597. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16598. }
  16599. void SetOcppConnStatus(uint8_t status)
  16600. {
  16601. ShmOCPP16DataPH->OcppConnStatus = status;
  16602. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16603. }
  16604. int GetHeartBeatWithNOResponse(void)
  16605. {
  16606. return HeartBeatWithNOResponse;
  16607. }
  16608. void SetHeartBeatWithNOResponse(void)
  16609. {
  16610. HeartBeatWithNOResponse = 0;
  16611. }
  16612. void GetStartTransactionIdTag(int gun_index)
  16613. {
  16614. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16615. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16616. }
  16617. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16618. {
  16619. char ch;
  16620. FILE *fptr1;
  16621. int temptransactionId;
  16622. char str[100]={0};
  16623. temptransactionId = 0;
  16624. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16625. {
  16626. DEBUG_INFO("IdTag is empty.\n");
  16627. return temptransactionId;
  16628. }
  16629. /*------ Read the file ----------------*/
  16630. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16631. if (!fptr1)
  16632. {
  16633. DEBUG_INFO("QueueTransactionId file open error.\n");
  16634. //printf(" File not found or unable to open the input file!!\n");
  16635. return temptransactionId;
  16636. }
  16637. ch=fgetc(fptr1);
  16638. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16639. rewind(fptr1);
  16640. if(ch!=EOF)
  16641. {
  16642. // printf("%c",ch);
  16643. while (fgets(str, 100, fptr1) != NULL)
  16644. {
  16645. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16646. if(str[0]=='\0')
  16647. {
  16648. break;
  16649. }
  16650. char *revbuf[8] = {0}; // Variable store string split
  16651. int num = 0;// Quantity after string split
  16652. DEBUG_INFO("Transaction queue data= %s\n", str);
  16653. splitstring(str,",",revbuf,&num); // String split
  16654. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16655. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16656. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16657. DEBUG_INFO("------------------------------\n");
  16658. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16659. {
  16660. if(isStopTransaction)
  16661. {
  16662. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16663. {
  16664. temptransactionId = atoi(revbuf[2]);
  16665. //break;
  16666. }
  16667. }
  16668. else
  16669. {
  16670. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16671. {
  16672. temptransactionId = atoi(revbuf[2]);
  16673. //break;
  16674. }
  16675. }
  16676. }
  16677. }
  16678. }
  16679. else
  16680. DEBUG_INFO("EOF\n");
  16681. fclose(fptr1);
  16682. /*------- End of reading ---------------*/
  16683. return temptransactionId;
  16684. }
  16685. void SetTransactionIdZero(int transactionId)
  16686. {
  16687. char ch;
  16688. FILE *fptr1, *fptr2;
  16689. int temptransactionId = 0;
  16690. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16691. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16692. if (!fptr1)
  16693. {
  16694. //printf(" File not found or unable to open the input file!!\n");
  16695. return ;
  16696. }
  16697. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16698. if (!fptr2)
  16699. {
  16700. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16701. fclose(fptr1);
  16702. return ;
  16703. }
  16704. ch=fgetc(fptr1);
  16705. rewind(fptr1);
  16706. if(ch!=EOF)
  16707. {
  16708. // copy all contents to the temporary file except the specific line
  16709. while (fgets(str, 100, fptr1) != NULL)
  16710. {
  16711. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16712. if(str[0]=='\0')
  16713. {
  16714. break;
  16715. }
  16716. char *revbuf[8] = {0};
  16717. int num = 0;
  16718. strcpy(strtemp, str);
  16719. splitstring(str,",",revbuf,&num);
  16720. if(revbuf[2][0] != '\0')
  16721. {
  16722. temptransactionId = atoi(revbuf[2]);
  16723. if(transactionId != temptransactionId)
  16724. {
  16725. fprintf(fptr2, "%s\n", strtemp);
  16726. }
  16727. }
  16728. }
  16729. }
  16730. fclose(fptr1);
  16731. fclose(fptr2);
  16732. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16733. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16734. /*------ Read the file ----------------*/
  16735. }
  16736. int InternetDisconnect(void)
  16737. {
  16738. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16739. }
  16740. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16741. void storeTempStopTransaction(int gun_index)
  16742. {
  16743. char guid[37]={0};
  16744. int tempIndex = 0;
  16745. char TempStopTransaction[256];
  16746. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16747. DEBUG_INFO("storeTempStopTransaction...\n");
  16748. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16749. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16750. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16751. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16752. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16753. {
  16754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16755. {
  16756. tempIndex = ((gun_index==2) ? 1: 0);
  16757. }
  16758. else
  16759. {
  16760. tempIndex = gun_index;
  16761. }
  16762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16763. {
  16764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16765. {
  16766. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16767. }
  16768. }// END OF CHAdeMO_QUANTITY
  16769. }
  16770. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16771. {
  16772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16773. {
  16774. tempIndex = ((gun_index==2) ? 1: 0);
  16775. }
  16776. else
  16777. {
  16778. tempIndex = gun_index;
  16779. }
  16780. for (int index = 0; index < CCS_QUANTITY; index++)
  16781. {
  16782. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16783. {
  16784. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16785. }
  16786. }// END OF CCS_QUANTITY
  16787. }
  16788. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16789. {
  16790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16791. {
  16792. tempIndex = ((gun_index==2) ? 1: 0);
  16793. }
  16794. else
  16795. {
  16796. tempIndex = gun_index;
  16797. }
  16798. for (int index = 0; index < GB_QUANTITY; index++)
  16799. {
  16800. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16801. {
  16802. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16803. }
  16804. }// END OF GB_QUANTITY
  16805. }
  16806. else if(gunType[gun_index] == GUN_TYPE_DO)
  16807. {
  16808. tempIndex = gun_index;
  16809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16810. {
  16811. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16812. {
  16813. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16814. }
  16815. }
  16816. }
  16817. else
  16818. {
  16819. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16820. {
  16821. tempIndex = 2;
  16822. }
  16823. else
  16824. {
  16825. tempIndex = gun_index;
  16826. }
  16827. for (int index = 0; index < AC_QUANTITY; index++)
  16828. {
  16829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16830. {
  16831. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16832. }
  16833. }// END OF AC_QUANTITY
  16834. }
  16835. //Stop Transaction Time
  16836. struct timeval tmnow;
  16837. struct tm *tm;
  16838. char buf[28];//, usec_buf[6];
  16839. gettimeofday(&tmnow, NULL);
  16840. time_t t;
  16841. t = time(NULL);
  16842. /*UTC time and date*/
  16843. tm = gmtime(&t);
  16844. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16846. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16848. random_uuid(guid);
  16849. /***********************************transactionData******************************************************/
  16850. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16852. //=================================
  16853. //1. Transaction_Begin
  16854. //=================================
  16855. //============================== Energy.Active.Import.Interval ===========================================
  16856. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16857. {
  16858. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16861. 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*/]);
  16862. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16863. 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))
  16864. {
  16865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16866. }
  16867. else
  16868. {
  16869. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16870. }
  16871. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16873. }
  16874. //=================================
  16875. //2. Transaction_End
  16876. //=================================
  16877. //2.1====================================== Current.Import L1 ==============================================
  16878. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16879. {
  16880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16881. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16882. {
  16883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16884. {
  16885. tempIndex = ((gun_index==2) ? 1: 0);
  16886. }
  16887. else
  16888. {
  16889. tempIndex = gun_index;
  16890. }
  16891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16892. {
  16893. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16894. {
  16895. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16896. }
  16897. }// End of for CHAdeMO_QUANTITY
  16898. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16899. }
  16900. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16901. {
  16902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16903. {
  16904. tempIndex = ((gun_index==2) ? 1: 0);
  16905. }
  16906. else
  16907. {
  16908. tempIndex = gun_index;
  16909. }
  16910. for (int index = 0; index < CCS_QUANTITY; index++)
  16911. {
  16912. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16913. {
  16914. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16915. }
  16916. }// End of for CCS_QUANTITY
  16917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16918. }
  16919. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16920. {
  16921. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16922. {
  16923. tempIndex = ((gun_index==2) ? 1: 0);
  16924. }
  16925. else
  16926. {
  16927. tempIndex = gun_index;
  16928. }
  16929. for (int index = 0; index < GB_QUANTITY; index++)
  16930. {
  16931. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16932. {
  16933. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16934. }
  16935. }// End of for GB_QUANTITY
  16936. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16937. }
  16938. else if(gunType[gun_index] == GUN_TYPE_DO)
  16939. {
  16940. tempIndex = gun_index;
  16941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16942. {
  16943. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16944. {
  16945. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16946. }
  16947. }
  16948. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16949. }
  16950. else
  16951. {
  16952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16953. {
  16954. tempIndex = 2;
  16955. }
  16956. else
  16957. {
  16958. tempIndex = gun_index;
  16959. }
  16960. for (int index = 0; index < AC_QUANTITY; index++)
  16961. {
  16962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16963. {
  16964. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16965. }
  16966. }// End of for AC_QUANTITY
  16967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16968. }
  16969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16972. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16975. }
  16976. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16977. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16978. {
  16979. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16980. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16981. {
  16982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16983. {
  16984. tempIndex = ((gun_index==2) ? 1: 0);
  16985. }
  16986. else
  16987. {
  16988. tempIndex = gun_index;
  16989. }
  16990. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16991. {
  16992. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16993. {
  16994. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16995. }
  16996. }// END OF CHAdeMO_QUANTITY
  16997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16998. }
  16999. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17000. {
  17001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17002. {
  17003. tempIndex = ((gun_index==2) ? 1: 0);
  17004. }
  17005. else
  17006. {
  17007. tempIndex = gun_index;
  17008. }
  17009. for (int index = 0; index < CCS_QUANTITY; index++)
  17010. {
  17011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17012. {
  17013. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17014. }
  17015. }// END OF CCS_QUANTITY
  17016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17017. }
  17018. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17019. {
  17020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17021. {
  17022. tempIndex = ((gun_index==2) ? 1: 0);
  17023. }
  17024. else
  17025. {
  17026. tempIndex = gun_index;
  17027. }
  17028. for (int index = 0; index < GB_QUANTITY; index++)
  17029. {
  17030. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17031. {
  17032. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17033. }
  17034. }// END OF GB_QUANTITY
  17035. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17036. }
  17037. else if(gunType[gun_index] == GUN_TYPE_DO)
  17038. {
  17039. tempIndex = gun_index;
  17040. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17041. {
  17042. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17043. {
  17044. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17045. }
  17046. }
  17047. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17048. }
  17049. else
  17050. {
  17051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17052. {
  17053. tempIndex = 2;
  17054. }
  17055. else
  17056. {
  17057. tempIndex = gun_index;
  17058. }
  17059. for (int index = 0; index < AC_QUANTITY; index++)
  17060. {
  17061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17062. {
  17063. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17064. }
  17065. }// END OF AC_QUANTITY
  17066. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17067. }
  17068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17069. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17071. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17074. }
  17075. //2.3====================================== Power.Active.Import =========================================
  17076. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17077. {
  17078. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17079. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17080. {
  17081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17082. {
  17083. tempIndex = ((gun_index==2) ? 1: 0);
  17084. }
  17085. else
  17086. {
  17087. tempIndex = gun_index;
  17088. }
  17089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17090. {
  17091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17092. {
  17093. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17094. }
  17095. } // End for CHAdeMO_QUANTITY
  17096. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17097. }
  17098. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17099. {
  17100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17101. {
  17102. tempIndex = ((gun_index==2) ? 1: 0);
  17103. }
  17104. else
  17105. {
  17106. tempIndex = gun_index;
  17107. }
  17108. for (int index = 0; index < CCS_QUANTITY; index++)
  17109. {
  17110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17111. {
  17112. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17113. }
  17114. } // END for CCS_QUANTITY
  17115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17116. }
  17117. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17118. {
  17119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17120. {
  17121. tempIndex = ((gun_index==2) ? 1: 0);
  17122. }
  17123. else
  17124. {
  17125. tempIndex = gun_index;
  17126. }
  17127. for (int index = 0; index < GB_QUANTITY; index++)
  17128. {
  17129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17130. {
  17131. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17132. }
  17133. }// END for GB_QUANTITY
  17134. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17135. }
  17136. else if(gunType[gun_index] == GUN_TYPE_DO)
  17137. {
  17138. tempIndex = gun_index;
  17139. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17140. {
  17141. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17142. {
  17143. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17144. }
  17145. }
  17146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17147. }
  17148. else
  17149. {
  17150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17151. {
  17152. tempIndex = 2;
  17153. }
  17154. else
  17155. {
  17156. tempIndex = gun_index;
  17157. }
  17158. for (int index = 0; index < AC_QUANTITY; index++)
  17159. {
  17160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17161. {
  17162. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17163. }
  17164. } // END for AC_QUANTITY
  17165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17166. }
  17167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17170. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17173. }
  17174. //2.4====================================== Voltage L1 ====================================================
  17175. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17176. {
  17177. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17178. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17179. {
  17180. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17181. {
  17182. tempIndex = ((gun_index==2) ? 1: 0);
  17183. }
  17184. else
  17185. {
  17186. tempIndex = gun_index;
  17187. }
  17188. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17189. {
  17190. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17191. {
  17192. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17193. }
  17194. } // END OF FOR CHAdeMO_QUANTITY
  17195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17196. }
  17197. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17198. {
  17199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17200. {
  17201. tempIndex = ((gun_index==2) ? 1: 0);
  17202. }
  17203. else
  17204. {
  17205. tempIndex = gun_index;
  17206. }
  17207. for (int index = 0; index < CCS_QUANTITY; index++)
  17208. {
  17209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17210. {
  17211. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17212. }
  17213. } // END OF FOR CCS_QUANTITY
  17214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17215. }
  17216. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17217. {
  17218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17219. {
  17220. tempIndex = ((gun_index==2) ? 1: 0);
  17221. }
  17222. else
  17223. {
  17224. tempIndex = gun_index;
  17225. }
  17226. for (int index = 0; index < GB_QUANTITY; index++)
  17227. {
  17228. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17229. {
  17230. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17231. }
  17232. } // END OF FOR GB_QUANTITY
  17233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17234. }
  17235. else if(gunType[gun_index] == GUN_TYPE_DO)
  17236. {
  17237. tempIndex = gun_index;
  17238. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17239. {
  17240. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17241. {
  17242. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17243. }
  17244. }
  17245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17246. }
  17247. else
  17248. {
  17249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17250. {
  17251. tempIndex = 2;
  17252. }
  17253. else
  17254. {
  17255. tempIndex = gun_index;
  17256. }
  17257. for (int index = 0; index < AC_QUANTITY; index++)
  17258. {
  17259. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17260. {
  17261. 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
  17262. }
  17263. } // END OF FOR AC_QUANTITY
  17264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17265. }
  17266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17269. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17272. }
  17273. //2.5============================================== End SoC =========================================================
  17274. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17275. {
  17276. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17277. 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))
  17278. {
  17279. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17280. {
  17281. tempIndex = ((gun_index==2) ? 1: 0);
  17282. }
  17283. else
  17284. {
  17285. tempIndex = gun_index;
  17286. }
  17287. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17288. {
  17289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17290. {
  17291. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17292. {
  17293. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17294. }
  17295. }
  17296. }
  17297. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17298. {
  17299. for (int index = 0; index < CCS_QUANTITY; index++)
  17300. {
  17301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17302. {
  17303. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17304. }
  17305. }
  17306. }
  17307. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17308. {
  17309. for (int index = 0; index < GB_QUANTITY; index++)
  17310. {
  17311. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17312. {
  17313. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17314. }
  17315. }
  17316. }
  17317. else if(gunType[gun_index] == GUN_TYPE_DO)
  17318. {
  17319. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17320. {
  17321. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17322. {
  17323. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17324. }
  17325. }
  17326. }
  17327. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17328. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17329. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17330. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17333. } // END FOR DC CASE
  17334. }
  17335. //2.6====================================== Current.Import L2 ==============================================
  17336. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17337. {
  17338. // AC 3 phase L2 current
  17339. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17340. {
  17341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17342. {
  17343. tempIndex = 2;
  17344. }
  17345. else
  17346. {
  17347. tempIndex = gun_index;
  17348. }
  17349. for (int index = 0; index < AC_QUANTITY; index++)
  17350. {
  17351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17352. {
  17353. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17354. }
  17355. }// End of for AC_QUANTITY
  17356. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17357. }
  17358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17359. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17363. }
  17364. //2.7====================================== Current.Import L3 ==============================================
  17365. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17366. {
  17367. // AC 3 phase L3 current
  17368. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17369. {
  17370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17371. {
  17372. tempIndex = 2;
  17373. }
  17374. else
  17375. {
  17376. tempIndex = gun_index;
  17377. }
  17378. for (int index = 0; index < AC_QUANTITY; index++)
  17379. {
  17380. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17381. {
  17382. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17383. }
  17384. }// End of for AC_QUANTITY
  17385. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17386. }
  17387. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17388. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17389. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17392. }
  17393. //2.9====================================== Voltage L2 ====================================================
  17394. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17395. {
  17396. // AC 3 phase L2 volatge
  17397. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17398. {
  17399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17400. {
  17401. tempIndex = 2;
  17402. }
  17403. else
  17404. {
  17405. tempIndex = gun_index;
  17406. }
  17407. for (int index = 0; index < AC_QUANTITY; index++)
  17408. {
  17409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17410. {
  17411. 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
  17412. }
  17413. } // END OF FOR AC_QUANTITY
  17414. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17415. }
  17416. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17417. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17418. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17419. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17420. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17421. }
  17422. //2.10====================================== Voltage L3 ====================================================
  17423. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17424. {
  17425. // AC 3 phase L3 volatge
  17426. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17427. {
  17428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17429. {
  17430. tempIndex = 2;
  17431. }
  17432. else
  17433. {
  17434. tempIndex = gun_index;
  17435. }
  17436. for (int index = 0; index < AC_QUANTITY; index++)
  17437. {
  17438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17439. {
  17440. 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
  17441. }
  17442. } // END OF FOR AC_QUANTITY
  17443. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17444. }
  17445. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17447. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17449. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17450. }
  17451. //====================== Start SoC ================================
  17452. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17453. {
  17454. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17455. 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))
  17456. {
  17457. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17458. {
  17459. tempIndex = ((gun_index==2) ? 1: 0);
  17460. }
  17461. else
  17462. {
  17463. tempIndex = gun_index;
  17464. }
  17465. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17466. {
  17467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17468. {
  17469. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17470. {
  17471. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17472. }
  17473. }
  17474. }
  17475. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17476. {
  17477. for (int index = 0; index < CCS_QUANTITY; index++)
  17478. {
  17479. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17480. {
  17481. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17482. }
  17483. }
  17484. }
  17485. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17486. {
  17487. for (int index = 0; index < GB_QUANTITY; index++)
  17488. {
  17489. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17490. {
  17491. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17492. }
  17493. }
  17494. }
  17495. else if(gunType[gun_index] == GUN_TYPE_DO)
  17496. {
  17497. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17498. {
  17499. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17500. {
  17501. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17502. }
  17503. }
  17504. }
  17505. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17511. } // END FOR DC CASE
  17512. }
  17513. //======================================== Message create ==============================================
  17514. json_object *StopTransaction = json_object_new_object();
  17515. json_object *transactionDatas = json_object_new_array();
  17516. json_object *sampledValues = json_object_new_array();
  17517. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17518. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17519. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17520. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17521. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17522. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17523. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17524. {
  17525. json_object *transactionData = json_object_new_object();
  17526. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17527. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17528. {
  17529. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17530. {
  17531. json_object *sampledValue = json_object_new_object();
  17532. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17533. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17534. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17535. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17536. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17537. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17538. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17539. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17540. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17541. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17542. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17543. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17544. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17545. json_object_array_add(sampledValues, sampledValue);
  17546. }
  17547. }
  17548. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17549. json_object_array_add(transactionDatas, transactionData);
  17550. }
  17551. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17552. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17553. ,MESSAGE_TYPE_CALL
  17554. ,guid
  17555. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17556. json_object_put(StopTransaction);
  17557. // Check File "TempStopTransaction" Exist
  17558. if((access(TempStopTransaction,F_OK))!=-1)
  17559. {
  17560. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17561. fclose(fopen(TempStopTransaction, "w"));
  17562. }
  17563. else
  17564. {
  17565. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17566. FILE *log = fopen(TempStopTransaction, "w+");
  17567. if(log == NULL)
  17568. {
  17569. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17570. return ;
  17571. }
  17572. else
  17573. {
  17574. fclose(log);
  17575. }
  17576. }
  17577. //Add TempStopTransaction | Update TempStopTransaction
  17578. // open file for writing
  17579. FILE *outfile;
  17580. outfile = fopen (TempStopTransaction, "a");
  17581. //DEBUG_INFO("data = %s\n", queuedata);
  17582. fputs(queuedata, outfile);
  17583. fputs("\n", outfile);
  17584. fclose (outfile);
  17585. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17586. }
  17587. void checkTempStopTransaction(int gun_index)
  17588. {
  17589. FILE *fptr1;
  17590. char ch;
  17591. char str[QUEUE_MESSAGE_LENGTH]={0};
  17592. char guid[37]={0};
  17593. char tempdata[65]={0};
  17594. char connectorStr[2]={0};
  17595. char TempStopTransaction[256];
  17596. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17597. fptr1 = fopen(TempStopTransaction, "r");
  17598. //TempStopTransaction格式: 槍號,StopTransaction封包
  17599. if (!fptr1)
  17600. {
  17601. //printf(" File not found or unable to open the input file!!\n");
  17602. return ;
  17603. }
  17604. ch=fgetc(fptr1);
  17605. //printf(" Now the content of the file %s is : \n",fname);
  17606. rewind(fptr1);
  17607. if(ch!=EOF)
  17608. {
  17609. // copy all contents to the temporary file except the specific line
  17610. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17611. {
  17612. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17613. if(str[0]=='\0')
  17614. {
  17615. break;
  17616. }
  17617. //TempStopTransaction格式: 槍號,StopTransaction封包
  17618. strncpy(connectorStr, str, 1);
  17619. if(atoi(connectorStr) != (gun_index+1))
  17620. {
  17621. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17622. fclose(fptr1);
  17623. return ;
  17624. }
  17625. //random_uuid(guid);
  17626. strncpy(guid, str+6, 36); //copy guid
  17627. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17628. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17629. {
  17630. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17631. }
  17632. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17633. OCPP_insert_transaction_msg(NO, str);
  17634. memset(str,0,ARRAY_SIZE(str));
  17635. }
  17636. }
  17637. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17638. fclose(fptr1);
  17639. remove(TempStopTransaction); // remove the original file
  17640. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17641. }
  17642. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17643. {
  17644. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17645. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17646. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17647. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17648. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17649. }
  17650. int GetWebSocketPingInterval(void)
  17651. {
  17652. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17653. }
  17654. int GetServerSign(void)
  17655. {
  17656. return server_sign;
  17657. }
  17658. uint8_t GetOcppSecurityProfile()
  17659. {
  17660. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17661. }
  17662. void GetOcppChargerBoxId(uint8_t *data)
  17663. {
  17664. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17665. }
  17666. void GetOcppSecurityPassword(uint8_t *data)
  17667. {
  17668. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17669. }
  17670. void SetOcppVersion(uint8_t *version)
  17671. {
  17672. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17673. DEBUG_INFO("ocpp version: %s\n", version);
  17674. if(strstr((char*)version, "ocpp1.6") != NULL)
  17675. {
  17676. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17677. }
  17678. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17679. {
  17680. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17681. system("pkill OcppBackend");
  17682. }
  17683. }
  17684. void SetServerSign(int value)
  17685. {
  17686. server_sign = value;
  17687. }
  17688. int GetBootNotificationInterval(void)
  17689. {
  17690. return BootNotificationInterval;
  17691. }
  17692. int GetInternetConn(void)
  17693. {
  17694. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17695. }
  17696. int GetBackendConnectionTimeout(void)
  17697. {
  17698. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17699. }
  17700. int isConnectorInitMode(int gun_index)
  17701. {
  17702. int tempIndex = 0;
  17703. int result = TRUE;
  17704. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17705. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17706. {
  17707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17708. {
  17709. tempIndex = ((gun_index==2) ? 1: 0);
  17710. }
  17711. else
  17712. {
  17713. tempIndex = gun_index;
  17714. }
  17715. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17716. {
  17717. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17718. {
  17719. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17720. } //end of the same index
  17721. }//end of for CHAdeMO_QUANTITY
  17722. }
  17723. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17724. {
  17725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17726. {
  17727. tempIndex = ((gun_index==2) ? 1: 0);
  17728. }
  17729. else
  17730. {
  17731. tempIndex = gun_index;
  17732. }
  17733. for (int index = 0; index < CCS_QUANTITY; index++)
  17734. {
  17735. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17736. {
  17737. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17738. } //end of the same index
  17739. } // end of for CCS_QUANTITY
  17740. }
  17741. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17742. {
  17743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17744. {
  17745. tempIndex = ((gun_index==2) ? 1: 0);
  17746. }
  17747. else
  17748. {
  17749. tempIndex = gun_index;
  17750. }
  17751. for (int index = 0; index < GB_QUANTITY; index++)
  17752. {
  17753. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17754. {
  17755. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17756. } //end of the same index
  17757. } // end of for GB_QUANTITY
  17758. }
  17759. else if(gunType[gun_index] == GUN_TYPE_DO)
  17760. {
  17761. tempIndex = gun_index;
  17762. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17763. {
  17764. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17765. {
  17766. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17767. } //end of the same index
  17768. }
  17769. }
  17770. else
  17771. {
  17772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17773. {
  17774. tempIndex = 2;
  17775. }
  17776. else
  17777. {
  17778. tempIndex = gun_index;
  17779. }
  17780. for (int index = 0; index < AC_QUANTITY; index++)
  17781. {
  17782. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17783. {
  17784. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17785. }//end of the same index
  17786. }//end of for AC_QUANTITY
  17787. }
  17788. return result;
  17789. }
  17790. void refreshProcDogTimer()
  17791. {
  17792. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17793. }
  17794. void InitialSystemValue(void)
  17795. {
  17796. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17797. locallistVersion=0;
  17798. BootNotificationInterval = 0;
  17799. authorizeRetryTimes = 0;
  17800. GunStatusInterval = 10;
  17801. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17802. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17803. //Hear Beat
  17804. HeartBeatWithNOResponse = 0;
  17805. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17806. FirstHeartBeat = 0;
  17807. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17808. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17809. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17810. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17811. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17812. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17813. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17814. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17815. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17816. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17817. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17818. //Status && ConnectorPlugIn Setting
  17819. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17820. {
  17821. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17822. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17823. }
  17824. for (int index = 0; index < CCS_QUANTITY; index++)
  17825. {
  17826. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17827. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17828. }
  17829. for (int index = 0; index < GB_QUANTITY; index++)
  17830. {
  17831. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17832. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17833. }
  17834. for (int index = 0; index < AC_QUANTITY; index++)
  17835. {
  17836. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17837. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17838. }
  17839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17840. {
  17841. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17842. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17843. }
  17844. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17845. {
  17846. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17847. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17848. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17849. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17850. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17851. }
  17852. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17853. refreshStartTimer(&clientTime.Heartbeat);
  17854. sleep(1);
  17855. }
  17856. void LWS_Send(char *str)
  17857. {
  17858. //=====================================================
  17859. // Check InternetConn 0: disconnected, 1: connected
  17860. //====================================================
  17861. if(GetOcppConnStatus() == 0)
  17862. {
  17863. DEBUG_INFO("offline now !!!\n");
  17864. return;
  17865. }
  17866. // Only disable isWebsocketSendable operation initiated by charger
  17867. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17868. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17869. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17870. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17871. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17872. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17873. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17874. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17875. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17876. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17877. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17878. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17879. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17880. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17881. {
  17882. isWebsocketSendable = 0;
  17883. }
  17884. pthread_mutex_lock(&lock_send);
  17885. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17886. sprintf((char *)SendBuffer, "%s", str);
  17887. SendBufLen = strlen(str);
  17888. pthread_mutex_unlock(&lock_send);
  17889. lws_callback_on_writable(wsi_client);
  17890. //lws_service(context, 0);
  17891. //sleep(1);
  17892. }
  17893. void LWS_SendNow(char *str)
  17894. {
  17895. //=====================================================
  17896. // Check InternetConn 0: disconnected, 1: connected
  17897. //====================================================
  17898. if(GetOcppConnStatus() == 0)
  17899. {
  17900. DEBUG_INFO("offline now !!!\n");
  17901. return;
  17902. }
  17903. // Only disable isWebsocketSendable operation initiated by charger
  17904. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17905. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17906. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17907. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17908. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17909. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17910. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17911. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17912. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17913. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17914. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17915. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17916. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17917. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17918. {
  17919. isWebsocketSendable = 0;
  17920. }
  17921. pthread_mutex_lock(&lock_send);
  17922. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17923. sprintf((char *)SendBuffer, "%s", str);
  17924. SendBufLen = strlen(str);
  17925. pthread_mutex_unlock(&lock_send);
  17926. lws_callback_on_writable(wsi_client);
  17927. lws_service(context, 0);
  17928. //sleep(1);
  17929. }